How can I get the result of this equation

A

Abder-Rahman Ali

I have written this a script like this:

values = [10, 20, 30].each {|value| value + (value * 10)}

puts value

In this case, I get:
undefined local variable or method `value' for main:Object (NameError)

I'm trying to see the result of the equation value + (value * 10)

What should I do?

Thanks.
 
J

James O'Brien

[Note: parts of this message were removed to make it a legal post.]

Ali,

I suspect the example you're trying was actually printing out
value*s*(...s! plural NOT value)

this would then make sense as a demonstration that the 'each' loop did not
alter the array

:)


On Wed, Jul 14, 2010 at 12:26 AM, Abder-Rahman Ali <
 
J

James O'Brien

[Note: parts of this message were removed to make it a legal post.]

more conclusively (using =)

array = [10,20,30]
array.each {|number| number = (number * 10)}
puts array
[10,20,30]
i.e. not [100,200,300]!

Ali,

I suspect the example you're trying was actually printing out
value*s*(...s! plural NOT value)

this would then make sense as a demonstration that the 'each' loop did not
alter the array

:)


On Wed, Jul 14, 2010 at 12:26 AM, Abder-Rahman Ali <
I have written this a script like this:

values = [10, 20, 30].each {|value| value + (value * 10)}

puts value

In this case, I get:
undefined local variable or method `value' for main:Object (NameError)

I'm trying to see the result of the equation value + (value * 10)

What should I do?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top