F
Frisco Del Rosario
I'm curious as to why the following does not create three instances of
class Cat:
class Cat
def initialize(name)
@name = name
end
end
toons = ["Felix", "Garfield", "Heathcliff"]
toons.each {|t| t = Cat.new(t)}
In irb, the last input and output are:
irb(main):008:0> toons.each {|t| t=Cat.new(t)}
=> ["Felix", "Garfield", "Heathcliff"]
which I don't understand.
class Cat:
class Cat
def initialize(name)
@name = name
end
end
toons = ["Felix", "Garfield", "Heathcliff"]
toons.each {|t| t = Cat.new(t)}
In irb, the last input and output are:
irb(main):008:0> toons.each {|t| t=Cat.new(t)}
=> ["Felix", "Garfield", "Heathcliff"]
which I don't understand.