I’m confused about the returning values in Ruby. For example, if I do
(1..5).each {|i| puts 2*i}
it returns
=> 1..5
I just don’t know why it happens. It seems sometimes it returns more than one variable?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Everything in ruby is an expression.* Expression has a value.
eachevaluates to the object it iterated. In this case it’s aRangeobject.Take a look at definition of Array#each:
For every element in the input array it calls the block, and then returns the input array.
* From the top of my head, I can’t name a thing in ruby that’s not an expression.