[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby alias problem

Alexander Rysenko

8/29/2006 6:50:00 AM

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-....

2 Answers

Eric Hodel

8/29/2006 6:56:00 AM

0

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

> 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

> 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.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...



Paul Lutus

8/29/2006 7:10:00 AM

0

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.ara...