I have two questions:
f_1 belong to the metaclass anonymous class?f_2 belong to the anonymous class?related to the following code:
car = "car"
class << car
def self.f_1
puts "f_1"
end
def f_2
puts "f_2"
end
end
Since ruby's own API uses the term "singleton class," I'd say the following are true:
f_1 is a class method on car's singleton class and can be called like this:
car.singleton_class.f_1
f_2 is an instance method on car's singleton class and can be called like this:
car.f_2
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