animal = "cat"
animal.instance_variable_set(:@a, "dog")
p animal.class.ancestors
p animal.method(:inspect)
# >> [String, Comparable, Object, Kernel, BasicObject]
# >> #<Method: String(Kernel)#inspect>
A) Object comes first in the ancestor chains. Why #inspect is then getting called from Kernel while Object#inspect exist ?
B) I didn't find Kernel#inspect here - http://ruby-doc.org/core-2.2.0/Kernel.html . So from where it is coming ?
.
I expected the output as #<Method: String(Object)#inspect>
···
--
Regards,
Arup Rakshit
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
Why do you think that #inspect is defined *IN* Object rather than coming from the Kernel module?
-Rob
···
On 2015-Mar-24, at 15:17 , Arup Rakshit <aruprakshit@rocketmail.com> wrote:
Hi,
class String
remove_method :inspect
end
animal = "cat"
animal.instance_variable_set(:@a, "dog")
p animal.class.ancestors
p animal.method(:inspect)
# >> [String, Comparable, Object, Kernel, BasicObject]
# >> #<Method: String(Kernel)#inspect>
A) Object comes first in the ancestor chains. Why #inspect is then getting called from Kernel while Object#inspect exist ?
B) I didn't find Kernel#inspect here - Module: Kernel (Ruby 2.2.0) . So from where it is coming ?
.
I expected the output as #<Method: String(Object)#inspect>
--
Regards,
Arup Rakshit
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
I think Arup is refering to the fact that theres an inspect method in
Object as the documentation states.
And there's no inspect method in Kernel documentation.
And if you ask to "toggle source" we see a method definition called
'rb_obj_inspect(VALUE obj)'
IMHO it's confusing.
In Kernel documentation we have a clue:
Abinoam Jr.
···
On Tue, Mar 24, 2015 at 6:04 PM, Rob Biedenharn <rob.biedenharn@gmail.com> wrote:
On 2015-Mar-24, at 15:17 , Arup Rakshit <aruprakshit@rocketmail.com> wrote:
Hi,
class String
remove_method :inspect
end
animal = "cat"
animal.instance_variable_set(:@a, "dog")
p animal.class.ancestors
p animal.method(:inspect)
# >> [String, Comparable, Object, Kernel, BasicObject]
# >> #<Method: String(Kernel)#inspect>
A) Object comes first in the ancestor chains. Why #inspect is then getting called from Kernel while Object#inspect exist ?
B) I didn't find Kernel#inspect here - Module: Kernel (Ruby 2.2.0) . So from where it is coming ?
.
I expected the output as #<Method: String(Object)#inspect>
--
Regards,
Arup Rakshit
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
I think Arup is refering to the fact that theres an inspect method in
Object as the documentation states.
And there's no inspect method in Kernel documentation.
And if you ask to "toggle source" we see a method definition called
'rb_obj_inspect(VALUE obj)'
IMHO it's confusing.
In Kernel documentation we have a clue:
···
===
Kernel
The Kernel module is included by class Object, so its methods are
available in every Ruby object.
The Kernel instance methods are documented in class Object while the
module methods are documented here.
These methods are called without a receiver and thus can be called in
functional form:
Highlighting
"... The Kernel instance methods are documented in class Object "
Abinoam Jr.
On Tue, Mar 24, 2015 at 11:23 PM, Abinoam Jr. <abinoam@gmail.com> wrote:
I think Arup is refering to the fact that theres an inspect method in
Object as the documentation states. Class: Object (Ruby 2.2.0)
And if you ask to "toggle source" we see a method definition called
'rb_obj_inspect(VALUE obj)'
IMHO it's confusing.
In Kernel documentation we have a clue:
Abinoam Jr.
On Tue, Mar 24, 2015 at 6:04 PM, Rob Biedenharn > <rob.biedenharn@gmail.com> wrote:
On 2015-Mar-24, at 15:17 , Arup Rakshit <aruprakshit@rocketmail.com> wrote:
Hi,
class String
remove_method :inspect
end
animal = "cat"
animal.instance_variable_set(:@a, "dog")
p animal.class.ancestors
p animal.method(:inspect)
# >> [String, Comparable, Object, Kernel, BasicObject]
# >> #<Method: String(Kernel)#inspect>
A) Object comes first in the ancestor chains. Why #inspect is then getting called from Kernel while Object#inspect exist ?
B) I didn't find Kernel#inspect here - Module: Kernel (Ruby 2.2.0) . So from where it is coming ?
.
I expected the output as #<Method: String(Object)#inspect>
--
Regards,
Arup Rakshit
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
Thanks for showing. I really don't know the actual intention of documenting methods of Kernel inside the Object. As per the Ruby documentation, Object#inspect(Class: Object (Ruby 2.2.1)) is basically Kernel#inspect. Well here something weird I found again.
"The default inspect shows the object’s class name, an encoding of the object id, and a list of the instance variables and their values (by calling inspect on each of them)."
And if you ask to "toggle source" we see a method definition called
'rb_obj_inspect(VALUE obj)'
IMHO it's confusing.
In Kernel documentation we have a clue:
===
Kernel
The Kernel module is included by class Object, so its methods are
available in every Ruby object.
The Kernel instance methods are documented in class Object while the
module methods are documented here.
These methods are called without a receiver and thus can be called in
functional form:
Highlighting
"... The Kernel instance methods are documented in class Object "
--
Regards,
Arup Rakshit
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.