R
rubyrus
Can anybody help me here, TIA!!
This is the code. I expect to see the string "Afterward:turkey", but
why am I getting "Afterward:camel"? |animal| parameter in a block
should be temporary inside the block, right??
Code:
----------
animal = "turkey"
puts "Original:" + animal
puts
["cow","camel"].each { |animal| puts "in block:" + animal }
puts
puts "Afterwards:" + animal
Output:
-----------
Original:turkey
in block:cow
in block:camel
Afterwards:camel
This is the code. I expect to see the string "Afterward:turkey", but
why am I getting "Afterward:camel"? |animal| parameter in a block
should be temporary inside the block, right??
Code:
----------
animal = "turkey"
puts "Original:" + animal
puts
["cow","camel"].each { |animal| puts "in block:" + animal }
puts
puts "Afterwards:" + animal
Output:
-----------
Original:turkey
in block:cow
in block:camel
Afterwards:camel