Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6045179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:05:45+00:00 2026-05-23T07:05:45+00:00

Feel free to delete this topic if it’s discussed or quite obvious. I hail

  • 0

Feel free to delete this topic if it’s discussed or quite obvious. I hail from C# background and I’m planning to learn Ruby. Everything I read about it seems quite intriguing. But I’m confused over this basic philosophy of Ruby that “there’s more than one way to do one thing”. Can someone provide 2 or 3 simple arithmetic or string examples to make this point clear, like if its about the syntaxes or logics etc.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:05:46+00:00Added an answer on May 23, 2026 at 7:05 am

    “More than one way of doing something” means having the choice of doing something the way you want it. That way you can use various programming styles, no matter what background you’re coming from.


    Iteration using for vs. blocks

    You can iterate over an array of things like so. This is pretty basic, and if you’re from a Java background, this feels kind of natural.

    for something in an_array
       print something
    end
    

    A more Ruby-like way would be the following:

    an_array.each do |something|
        print something
    end
    

    The first is a rather well known way of doing things. The second one is using blocks, a very powerful concept that you’ll find in many Ruby idioms. Basically, the array knows how to iterate over its contents, so you can modify this and add something like:

    an_array.each_with_index do |something, index|
        print "At #{index}, there is #{something}"
    end
    

    You could have done it like this too, but now you see that the above one looks easier:

    index = 0
    for something in an_array
        print "At #{index}, there is #{something}"
        index += 1
    end
    

    Passing arguments as usual or using Hashes

    Normally, you would pass arguments like so:

    def foo(arg1, arg2, arg3)
        print "I have three arguments, which are #{arg1}, #{arg2} and #{arg3}"
    end
    
    foo("very", "easy", "classic")
    
    => "I have three arguments, which are very easy and classic"
    

    However, you may also use a Hash to do that:

    def foo(args)
        print "I have multiple arguments, they are #{args[:arg1]}, #{args[:arg2]} and #{args[:arg3]}"
    end
    
    foo :arg1 => "in a", :arg2 => "hash", :arg3 => "cool"
    
    => "I have three arguments, which are in a hash and cool"
    

    The second form is one used excessively by Ruby on Rails. The nice thing is that you now have named parameters. When you are passing them, you will more easily remember what they are used for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT-Moderator, feel free to delete this question. The problem lay in my background image
I'm new to the stackoverflow so feel free to delete this question if it's
My issue was a missing comma. Feel free to delete this post while I
Feel free to close and/or redirect if this has been asked, but here's my
Please feel free to move this to meta/superuser if this is the wrong place.
Sorry for bumpy topic name (feel free to edit if you find more fitting
If this is not a real question then feel free to close ;)
Forgive me if this has already been asked (and feel free to provide a
I'm not sure this is the right forum if it's not please feel free
I haven't found this question, feel free to close if it's already up here.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.