Ruby alias problem

Discussion in 'Ruby' started by Alexander Rysenko, Aug 29, 2006.

  1. 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/.
     
    Alexander Rysenko, Aug 29, 2006
    #1
    1. Advertising

  2. Alexander Rysenko

    Eric Hodel Guest

    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 - - http://blog.segment7.net
    This implementation is HODEL-HASH-9600 compliant

    http://trackmap.robotcoop.com
     
    Eric Hodel, Aug 29, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. remz
    Replies:
    0
    Views:
    468
  2. grocery_stocker
    Replies:
    9
    Views:
    790
    grocery_stocker
    May 24, 2008
  3. korte

    Alias problem

    korte, Dec 7, 2009, in forum: VHDL
    Replies:
    0
    Views:
    533
    korte
    Dec 7, 2009
  4. jney
    Replies:
    2
    Views:
    159
    Jean-S├ębastien
    Sep 4, 2009
  5. Tron Fu
    Replies:
    4
    Views:
    180
    Tron Fu
    Aug 30, 2010
Loading...

Share This Page