Ruby alias problem

I have a class like this:

class Control
  attr_accessor :name, :parent, :children
  alias [] getChild

  def initialize(name)
    self.name = name
    @children = Hash.new
  end

  def addChild(child)
    child.parent = self
    @children[child.name] = child
  end

  def getChild(name)
    @children[name]
  end
end

So i want to alias method named getChild as []. But Ruby says "undefined
method `getChild' for class `Control'". How can I make such alias?

···

--
Posted via http://www.ruby-forum.com/.

I have a class like this:

class Control
  attr_accessor :name, :parent, :children

  def initialize(name)
    self.name = name
    @children = Hash.new
  end

  def addChild(child)
    child.parent = self
    @children[child.name] = child
  end

  def getChild(name)
    @children[name]
  end

   alias getChild

···

On Aug 28, 2006, at 11:49 PM, Alexander Rysenko wrote:

end

So i want to alias method named getChild as . But Ruby says "undefined
method `getChild' for class `Control'". How can I make such alias?

--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

Alexander Rysenko wrote:

I have a class like this:

/ ...

So i want to alias method named getChild as . But Ruby says "undefined
method `getChild' for class `Control'". How can I make such alias?

Locate the alias specification after "getChild" has been defined.

···

--
Paul Lutus
http://www.arachnoid.com