Creating a method like Array(object)

What you can do, though, use instead of ().

class YourClass
  class << self
    def (*args)
       p args
    end
  end
end

Then at least YourClass[1, 2, 3] would be available for you.

Gennady.

···

-----Original Message-----
From: Farrel Lifson [mailto:farrel.lifson@gmail.com]
Sent: Thursday, May 11, 2006 1:05
To: ruby-talk ML
Subject: Re: Creating a method like Array(object)

Whoops! Never mind just realised Array() isn't a class it's a
method on Kernel.

Hi Gennady,

You can define a method with the same name as a constant as they're in
separate namespaces, e.g.

class MyClass
  def initialize(*args, &block)
     p args
  end
end

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

o = MyClass(1,2,3)
p o
#=> #<MyClass:0x2c87910>

As the OP says, Array() is just a method on Kernel.

Regards,

Sean

···

On 5/11/06, Gennady Bystritsky <Gennady.Bystritsky@quest.com> wrote:

What you can do, though, use instead of ().