The === is a more broad definition to ==. If the two objects to compare are String, Number, the === is equal to ==.
If the left value is regular expression, the === is equal to =~. The case / when is using the === to match values.
The equal? method used to compare whether two objects are equal. Actually, the implementation of it is to compare the two values’s object_id.
We use eql? to compare two object’s values. In most cases, the eal? is equal to ==, but the number is an exception. 1.0 == 1 is true, but 1.0.eql? 1 is false. When using a number as a hash key, we should notice 1.0 is not equal to 1, they are two different keys because the Hash use eql? to compare its keys.
The Method and Proc are similar. The only difference is theirs executing environment. Methods run in an object’s scope and Proc run where they are declared.
If we invoke instance_method to a class or module, we can get an unbound method.
A class’s unbound methods can only bind the instances from its class or subclasses. If the unbound method from a module, it can bind any classes’s instances.
We can pass an unbound method to the define_method to implement dynamic binding.
class << Person self# The meta class of the class Person deftype puts "Person" end end # The meta class's instance method is the Person's class method. Person.type # => Person
me = Person.new # Accessing an object's meta class. class << me defrun puts 'running' end end me.run # => running
When instance_eval is used, new methods are defined on the metaclass, but the self is the object itself.