>> Object.methods.size
=> 85
>> def i_is_in_ur_Object; "kthxbai" end
=> nil
>> Object.methods.size
=> 86
>> String.new.i_is_in_ur_Object
=> "kthxbai"
Careful what you put in there!
>> Object.methods.size
=> 85
>> def i_is_in_ur_Object; "kthxbai" end
=> nil
>> Object.methods.size
=> 86
>> String.new.i_is_in_ur_Object
=> "kthxbai"
Careful what you put in there!
Filed under ruby
| Ebow on Ruby on V8 | |
| AofgkJ on Don’t you wanna feel the… | |
| WlasfM on Staying Alive with Thin! | |
| Robby Colvin on Defensio on Rails | |
| Paul Klipp on Rack, the frameworks fram… |
Blog at WordPress.com. | Theme: Pressrow by Chris Pearson.
2 Comments
August 8, 2008 at 12:35 pm
Actually, you’re in Kernel, which gets included in Object:
irb(main):001:0> Kernel.methods.size
=> 147
irb(main):002:0> def i_is_in_ur_Object; “kthxbai” end
=> nil
irb(main):003:0> Kernel.methods.size
=> 148
irb(main):004:0> Object.included_modules
=> [Wirble::Shortcuts, PP::ObjectMixin, Kernel]
August 8, 2008 at 1:49 pm
no, that’ because Kernel also inherit from Object
>> class Poop; end
>> def i_is_in_ur_Object; “kthxbai” end
>> Poop.method_defined?(:i_is_in_ur_Object)
=> true
You can see that you really are in an instance of Object:
>> self.class
=> Object
And in YARV’s code in vm.c around line 1884:
void
Init_top_self(void)
{
rb_vm_t *vm = GET_VM();
vm->top_self = rb_obj_alloc(rb_cObject);
rb_define_singleton_method(rb_vm_top_self(), “to_s”, main_to_s, 0);
}
vm->top_self is indeed an instance of Object and to_s rly outputs “main”