From: "Brian Schröder" Date: 2005-10-27T23:56:45+09:00 Subject: Re: obj() On 27/10/05, Daniel Schierbeck wrote: > Would this be possible: > > class Klass > def self.[] (*args) > new(*args) > end > end > > # these should do the same > Klass("foo", "bar") # new > Klass["foo", "bar"] # current > > obj = proc { |a, b| puts a + b } > > # these should do the same > obj("a", "b") # new > obj["a", "b"] # current > > It does have some complications, but it is a way to make Proc's seem > like normal methods. > > > Just an idea > Daniel > > At least the first is already possible: class Klass def initialize(*args) @args = args end def self.[] (*args) new(*args) end end def Klass(*args) Klass.new(*args) end # these should do the same p Klass("foo", "bar") # new p Klass["foo", "bar"] # current regards, Brian -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/