Suppose I have the following simple class:
class C
p self # => C
def self.foo
puts "foo"
end
def bar
puts "bar"
end
end
p C.foo # => "foo"
p C.bar # => "`<main>': undefined method `bar' for C:Class (NoMethodError)"
I know that self.foo
defines foo
to be an instance method inside the singleton class of C
.
Why does the second method not get defined inside the singleton class of C
like the first one? self
is still C
when this method is defined.