In the top-level :
unbinded_method = method :puts
#=> Object(Kernel)#puts(*arg1)
but I did this
obj = Object.new
obj.puts 'wow'
I got an undefined error
so I assumed the Kernel module didn’t include in the singleton class of obj, so I did
obj.instance_eval do
include Kernel
end
but I got error again:
NoMethodError: undefined method `include' for #<Object:0x00000100b14dc8>
Uhm, you can:
Note: obviously,
includeingKernelinto an instance ofObjectdoesn’t actually do anything, becauseKernelis already in the ancestor chain, and mixins can only appear once in the ancestor chain. But if youincludeanother mixin, that will work:No, you didn’t. This is the error you got:
It tells you right there in the error what the problem is:
Kernel#putsis private, and in Ruby, private methods can only be invoked as the result of a receiverless message send. For example like this:or just
Why did you assume instead of just check?
Again, the error message already tells you everything you need to know:
Objectdoesn’t have anincludemethod, nor is there one in its ancestor chain.includeis a method of theModuleclass, butobjis anObject, not aModule.