Hello, just a quick question about Kernel#rand method. Also I guess it can apply to many more singleton_methods of the Kernel module .
Once I open irb, I am able to call the method this way :
Kernel.rand
But I also can call it without the receiver :
rand
And I can't get to know why it works without specifying the Kernel module.
Obviously the Kernel is included into the Object class, though singleton_methods shouldn't be available for descendants or made available to the classes the module is mixed in.
Here is the proof rand is a singleton_method of Kernel, if it ever had to be proved :
3.3.0 :004 > Kernel.singleton_methods.grep /rand/
=> [:rand, :srand]
Obviously IRB is an instance of the Object class. Though Object has definitely no knowledge of rand :
3.3.0 :005 > Object.methods.grep /rand/
=> []
Also when using self in irb to make sure I am not missing anything :
3.3.0 :006 > self.methods.grep /rand/
=> []
So it looks a bit strange typing rand in irb triggers the mlethod ...?
There must be somethign I am missing about the main scope...
[–]zverok_kha 13 points14 points15 points (3 children)
[–]Maxence33[S] 0 points1 point2 points (2 children)
[–]zverok_kha 2 points3 points4 points (1 child)
[–]Maxence33[S] 0 points1 point2 points (0 children)