>> 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!
You’re just in a giant Object.class_eval block
Filed under ruby
>> 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!
Share this:
Filed under ruby
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]
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”