Time.now, it calls the method in anonymous class and
no more in Time class.
No, this code doesn’t change where the ‘now’ method resides. Time.now
always calls the ‘now’ method in its singleton class.
How this works ?
It works because Time is an object as well as a class. So Time can
(and does) have a singleton class (what you call an object-specific
class) just as any other object can. The singleton class of a class
is where class methods are defined, so the code you show simply
overrides the Time class method ‘now’.
…but only as a trivia answer as it relates to the implementation
details of MRI – the Matz Ruby Interpretter (aka, CRuby). It would
be quite bad form to rely on this “fact” for any code that you
expected to be portable.
Yes, it is.
Now it is in MRI and JRuby, but it definetly does not need to be
R.
I find it a little bit amusing that 4 is considered unlucky in
Japanese language, because of its implication of death - “shi”. 9 is
unlucky too for different reasons.
Elsewise; obviously, no design should rely upon object ids. I was
just curious. On top of that, I like the fact that in irb, the code
that I posted previously yields a visual contradiction. You can make
it more obvious by having the puts methods output “yes” and “no”.
Todd
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.