On Feb 25, 9:54 am, Eckie Silapaswang <eckie2... / gmail.com> wrote:
> The lines of particular interest to me are the
>
> def self.create_from_hash(hash)
>
> and the
>
> class << self
>   def create_from_hash(hash)
[snip]
> My questions to all the Rubyists out there is, do you have a particular
> preference between the two choices?  Is this a style issue?  Or is there
> really a concrete "it depends on this" factor?

I personally prefer the former, as I think any sane person would.
Imagine that you're scrolling through some code and see:
  def foo( bar )
and I ask you "Quick! Is that a 'class' method or an instance method?"

If you only use the former style, you know immediately that it's an
instance method. If you use the latter style, you need to scan up to
the top of the class, looking at every line and possibly indentation
to see if maybe you're inside the singleton class or not.

The only time I use class << self in a class definition is for the
simple, few-line:
  class << self
    attr_accessor :foo, :bar
  end