In message "Re: ruby-dev summary 23459-23562"
on 04/05/26, Florian Gross <flgr / ccan.de> writes:
|1) What will yield(*[]) do?
Same as "yield", not value attached.
|2) What will happen with these examples?
|
| define_method(:foo) { |arg| result = arg }
| foo(5); result # => 5 or ~> NameError?
5. There will be no in-block variables.
| # Or more interesting:
| define_method(:foo) { foo = nil; return true }
| foo # => true or nil or NameError?
| foo # => true or nil?
nil. You will need to declare method local variables inside of
methods defined by define_method, for example:
define_method(:foo) {local{|foo=nil| return true}}
|3) What will happen with these examples?
|
| [1, 2, 3].each do |item|
| [1, 2, 3].each do |item|
| # Exception or reassignment of outer item or
| # own private inner item?
| end
| end
Error (by shadowing variable) or warning.
| [1, 2, 3].each do |item|
| [1, 2, 3].each do |inner_item|
| item += 1 if item == inner_item
| end
| p item
| end
It will print 4,4,4, as it does now.
matz.