I'm looking at this code in a Ruby library.
Am I correct in assuming that self.class.delete
calls the class method called delete
on the current object - i.e. the object referenced by self
.
def delete!
self.class.delete(self.key)
end
It calls the class method delete
for the class of self.
class Example
def self.delete
puts "Class method. 'self' is a " + self.class.to_s
end
def delete!
puts "Instance method. 'self' is a " + self.class.to_s
self.class.delete
end
end
Example.new.delete!
Outputs:
Instance method. 'self' is a Example Class method. 'self' is a Class
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