I have the following piece of code:
class Fish
# @message = "I can swim"
class << self
@message = "I can jump!"
define_method(:action) { @message }
end
end
Fish.action => nil
As soon as I uncomment the above @message variable, Fish.action returns I can swim. Why in both cases it is ignoring the I can jump message. Why is that? Why is Fish class being binded to the @message defined at the start but not inside the singleton class?
actionoutside the singleton class and define it (equivalently)def self.action; @message; end, the answers to the earlier question would apply to your question as well.