On 2/28/07, Phrogz <gavin / refinery.com> wrote: > 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 > > Mainstream, mainstream, ... I think there is some semantic information conveyed, which of course is very personal. When I write class C <methods & friends> class << self end end this marks a unit class C <methods & friends> end class << C end that is somehow strange though I use it a lot because the code seems more readable but it marks a seperation, I just recently tried to understand Facet's philosophy of spreding classes and modules all over the place, sometimes this gives great flexibility when coming to maintenance per consequence on could write the two blocks into two different files Sometimes I use classes or modules only as namespaces than I want to show off that I am not sane (which is a virtue of course ;) class << C = Class.new( WhateverSuperClass ) end or class << M = Module.new end instead of C Class.new... class << C actually there are minor inconveniences for each notation. Robert -- We have not succeeded in answering all of our questions. In fact, in some ways, we are more confused than ever. But we feel we are confused on a higher level and about more important things. -Anonymous