On 10/27/05, Daniel Schierbeck <daniel.schierbeck / gmail.com> wrote:
> Would this be possible:
>
> class Klass
>   def self.[] (*args)
>     new(*args)
>   end
> end

The usual idiom I've seen (and used) is:

class Klass
  class<<self
    alias :[] :new
  end
end

>
> # these should do the same
> Klass("foo", "bar") # new

You can already do this:

def Klass(*args, &block)
  Klass.new(*args, &block)
end

See the discussion starting ruby-talk/160664.

> obj = proc { |a, b| puts a + b }
>
> # these should do the same
> obj("a", "b") # new

I think this is already in 1.9

Regards,

Sean