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?
On Aug 28, 2006, at 11:49 PM, Alexander R. wrote:
def addChild(child)
child.parent = self
@children[child.name] = child
end
def getChild(name)
@children[name]
end
alias [] getChild
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 H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant
http://trackmap.robotcoop.com
Alexander R. 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.