On 05/13/2013 12:01 PM, Magnus Holm wrote:
...
>     jballanc (Joshua Ballanco) wrote:
>      > If we remove the ability to call methods with (({::})), then the
>     class definition lines don't match as nicely:
>      >
>      >     class Baz < Foo::Bar
>      >     ...
>      >     class Quux < Foo.Bar("Howdy")
>      >     ...
>      >
...
> Can't you use use #[] for this?
>
>    class Quuz < Foo::Bar["Howdy"]
>    end
>
>    class User < Sequel::Model[:User]
>    end
>
>    doc = Nokogiri::XML[data]

As a bonus, the use of #[] (a method called on an object), rather than 
function call syntax, is more flexible. Compare:

   module Foo
     module Bar
       class Howdy; end
       def self.[] str
         const_get str
       end
     end
     def self.Bar str
       Bar.const_get str
     end
   end

   fubar = Foo::Bar
   class Quuz < fubar["Howdy"] # decoupled from assignment to fubar
   end
   p Quuz.ancestors[1] # ==> Foo::Bar::Howdy

   class Quuz2 < Foo::Bar("Howdy")
   end
   p Quuz2.ancestors[1] # ==> Foo::Bar::Howdy

You could of course do

   fubar = Foo.method(:Bar)
   class Quuz2 < fubar.call("Howdy")
     ...

but then fubar is just a callable, not a module.

Also note the cleaner (IMHO) encapsulation in Bar when using #[].