Vincent F. schrieb:
I vote for the last one too !
Vince
An additional method “Kernel#origin(name)” will be helpful, if the
method is
defined as a singleton method for an object, it is difficult to get the
object_id of the anonymous class, where the method ist defined (I hope
this
sentense is somehow understndable).
The object_id is necessary in comparisons with the result of the call to
the
method of class “Method”, that returns the associated class.
Here is some code as an example for the problem (if I didn’t make some
conceptional errors):
class Otto
end
p Otto # => Otto
puts “%x” % Otto.object_id # => 1574ecc
otto = Otto.new
puts “%x” % otto.object_id # => 1574d96
class <<otto
p self # =>
#<Class:#Otto:0x2ae9b2c>
puts “%x” % self.object_id # => 1574d78
def hi
puts “‘Hi!’ from ‘otto’”
end
end
p otto.class # => Otto
puts “%x” % otto.class.object_id # => 1574ecc
p otto.class.superclass # => Object
puts “%x” % otto.class.superclass.object_id # => 15386b6
myottohi = otto.method(:hi)
myottohi[] # => ‘Hi!’ from ‘otto’
p myottohi # => #<Method:
#Otto:0x2ae9b2c.hi>
Wolfgang Nádasi-Donner