From: Abder-Rahman Ali on 13 Jul 2010 19:26 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. -- Posted via http://www.ruby-forum.com/.
From: Kenneth on 13 Jul 2010 19:33 http://www.ruby-forum.com/topic/213052 -- Posted via http://www.ruby-forum.com/.
From: Abder-Rahman Ali on 13 Jul 2010 19:42 Kenneth wrote: > http://www.ruby-forum.com/topic/213052 Thanks Kenneth :-) -- Posted via http://www.ruby-forum.com/.
From: James O'Brien on 13 Jul 2010 20:12 [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 < abder.rahman.ali(a)gmail.com> wrote: > 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. > -- > Posted via http://www.ruby-forum.com/. > >
From: James O'Brien on 13 Jul 2010 20:18 [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]! On Wed, Jul 14, 2010 at 1:12 AM, James O'Brien <jeob32(a)gmail.com> wrote: > 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 < > abder.rahman.ali(a)gmail.com> wrote: > > > 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. > > -- > > Posted via http://www.ruby-forum.com/. > > > > >
|
Pages: 1 Prev: [ANN] unicorn 1.0.1 and 1.1.2 - fix rollbacks Next: Strange Loop 2010 |