Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Ruby alias problem

Reply
Thread Tools

Ruby alias problem

 
 
Alexander Rysenko
Guest
Posts: n/a
 
      08-29-2006
I have a class like this:

class Control
attr_accessor :name, arent, :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/.

 
Reply With Quote
 
 
 
 
Eric Hodel
Guest
Posts: n/a
 
      08-29-2006
On Aug 28, 2006, at 11:49 PM, Alexander Rysenko wrote:

> I have a class like this:
>
> class Control
> attr_accessor :name, arent, :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 - http://www.velocityreviews.com/forums/(E-Mail Removed) - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Broken alias behavior in Ruby 1.9.2? Tron Fu Ruby 4 08-30-2010 02:35 PM
declare a shell alias in a ruby file jney Ruby 2 09-04-2009 08:32 AM
reference/alias in perl vs reference/alias in C++ grocery_stocker C++ 9 05-24-2008 04:32 AM
XP X64 Pro, IE7, Delphi 2007, IntraWeb, MS Access, ODBC Alias problem: Insufficient memory for this operation. Alias: SomeDatabase. Skybuck Flying Windows 64bit 13 01-09-2008 07:34 PM
problem with alias directive and tomcat remz Java 0 02-06-2004 06:58 PM



Advertisments