Hot to call to any parent class method?

Discussion in 'Ruby' started by Iñaki Baz Castillo, May 6, 2008.

  1. SGksIEkndmUgbW9kaWZpZWQgImRlbGV0ZSIgY2xhc3MgaW4gTXlBcnJheSBjbGFzcyBidXQgaW4g
    b3RoZXIgY3VzdG9tCm1ldGhvZCBJIG5lZWQgdG8gY2FsbCB0byBpcmlnaW5hbCAiZGVsZXRlIiBt
    ZXRob2QuCldlbGwgSSBrbm93IHRoYXQgSSBjYW4gZG86CgogIGFsaWFzIG9yaWdpbmFsX2RlbGV0
    ZSBkZWxldGUKCiBkZWYgZGVsZXRlKHYpCiAgICAgLi4ubXlfc3R1ZmYuLi4KICBlbmQKCiAgZGVm
    IG90aGVyX21ldGhvZAogICAgIC4uLgogICAgIG9yaWdpbmFsX2RlbGV0ZSAuLi4KICBlbmQKCmVu
    ZAoKCkJ1dCwgY291bGQgSSBkbyB0aGUgc2FtZSB3aXRob3V0IHVzaW5nIGFuIGFsaWFzPyBjb3Vs
    ZCBJIGNhbGwgZGlyZWN0bHkKdG8gYSBwYXJlbnQgKEFycmF5KSBtZXRob2QgZnJvbSBhbnkgbWVo
    dG9kIG9mIHRoZSAic29vbiIgY2xhc3M/CgotLSAKScOxYWtpIEJheiBDYXN0aWxsbwo8aWJjQGFs
    aWF4Lm5ldD4K
     
    Iñaki Baz Castillo, May 6, 2008
    #1
    1. Advertising

  2. I've found this way...

    class ClassA
    def method1
    puts "From classA"
    end
    end

    class ClassB < ClassA
    def method1
    puts "From classB"
    end

    def method2
    self.class.superclass.instance_method:)method1).bind(self).call
    end
    end

    ClassB.new.method2

    On Tue, May 6, 2008 at 9:46 AM, I=F1aki Baz Castillo <> wrote:
    > Hi, I've modified "delete" class in MyArray class but in other custom
    > method I need to call to iriginal "delete" method.
    > Well I know that I can do:
    >
    > alias original_delete delete
    >
    > def delete(v)
    > ...my_stuff...
    > end
    >
    > def other_method
    > ...
    > original_delete ...
    > end
    >
    > end
    >
    >
    > But, could I do the same without using an alias? could I call directly
    > to a parent (Array) method from any mehtod of the "soon" class?
    >
    > --
    > I=F1aki Baz Castillo
    > <>
    >




    --=20
    Go outside! The graphics are amazing!
     
    Sandro Paganotti, May 6, 2008
    #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. mobi999
    Replies:
    0
    Views:
    784
    mobi999
    Jun 9, 2007
  2. Sandy Miller

    Java EE Developer-HOT HOT OPENINGS

    Sandy Miller, Jan 8, 2008, in forum: Java
    Replies:
    0
    Views:
    389
    Sandy Miller
    Jan 8, 2008
  3. Sandy Miller
    Replies:
    0
    Views:
    365
    Sandy Miller
    Jan 17, 2008
  4. Sandy Miller
    Replies:
    0
    Views:
    560
    Sandy Miller
    Jan 28, 2008
  5. Sandy Miller
    Replies:
    0
    Views:
    403
    Sandy Miller
    Feb 1, 2008
Loading...

Share This Page