From: Phrogz Date: 2008-02-15T08:14:56+09:00 Subject: Re: object specific methods and id On Feb 14, 3:59 pm, UpsNDowns wrote: > If I create an object specifc method foo on my string instance obj, a > new anonymous class (the singleton, I gather) is created and obj is > considered an instance of that. > > Also, every thing is an object (event classes). So how come, > obj.class.id > and > "someString".class.id > is the same? You should be using object_id; but that won't change what you see. > According to the documentation on id: "The same number will be returned > on all calls to id for a given object, and no two active objects will > share an id." Creating an eigenclass (singleton class) for an object does not change the .class of that object. irb(main):001:0> s1 = "hello" => "hello" irb(main):002:0> s2 = "world" => "world" irb(main):003:0> def s2.special_method; end => nil irb(main):004:0> s1.class == s2.class => true irb(main):005:0> s1.class => String irb(main):006:0> s2.class => String irb(main):008:0> s2eigenclass = class << s2; self; end => #> irb(main):012:0> s2.class.instance_methods.grep /special/ => [] irb(main):013:0> s2eigenclass.instance_methods.grep /special/ => ["special_method"]