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...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Ruby alias problem
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password