class Foo
def self.one; 1 end
class << self
def two; 2 end
end
end
puts Foo.singleton_methods.inspect # => [\"two\", \"one\"]
I\'
In application, there is no difference. In concept, the difference is subtle, but in the first case, you are operating in the current context, and defining a method on another class instance (actually, an instance method in its Eigenclass), whereas in the second case, you are entering the context of the the metaclass ("Eigenclass") of other class instance, and then defining an instance method.
Edit:
I should add that the reasons for choosing the class << self
in some cases are...
def my_method ...
. You can, for instance, say attr_accessor :some_attribute
in that block of code.