Singleton method is a method that is defined only on one instance.
foo = Foo.new
def foo.case
#singleton method
end
Doesn't instance_eval
do the same thing? Defining a method for a particular instance? What is the difference?
Object#instance_eval
is a method, using which you indeed can define method for an object.
Singleton class is a "place", where the singleton method defined for the object "lives".
So these are two absolutely different things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With