On Apr 8, 12:08 pm, Infinit Blue <infinitb... / gmail.com> wrote:
> For example I hv the following code:
>
> def test
>   n = 1
>   yield(n)
>   puts n
> end
>
> --------
> test {|x| x = x + 1; puts x}
>
> the output is:
> 2
> 1
>
> How can I modify the parameter x in block?
>
> Appreciate for your help.
> --
> Posted viahttp://www.ruby-forum.com/.

brian@airstream:~$ irb
irb(main):001:0> def test
irb(main):002:1> n = 1
irb(main):003:1> n = yield(n)
irb(main):004:1> puts n
irb(main):005:1> end
=> nil
irb(main):006:0> test {|x| x += 1; puts x; x }
2
2
=> nil