Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Hot to call to any parent class method?

Reply
Thread Tools

Hot to call to any parent class method?

 
 
Iñaki Baz Castillo
Guest
Posts: n/a
 
      05-06-2008
SGksIEkndmUgbW9kaWZpZWQgImRlbGV0ZSIgY2xhc3MgaW4gTX lBcnJheSBjbGFzcyBidXQgaW4g
b3RoZXIgY3VzdG9tCm1ldGhvZCBJIG5lZWQgdG8gY2FsbCB0by BpcmlnaW5hbCAiZGVsZXRlIiBt
ZXRob2QuCldlbGwgSSBrbm93IHRoYXQgSSBjYW4gZG86CgogIG FsaWFzIG9yaWdpbmFsX2RlbGV0
ZSBkZWxldGUKCiBkZWYgZGVsZXRlKHYpCiAgICAgLi4ubXlfc3 R1ZmYuLi4KICBlbmQKCiAgZGVm
IG90aGVyX21ldGhvZAogICAgIC4uLgogICAgIG9yaWdpbmFsX2 RlbGV0ZSAuLi4KICBlbmQKCmVu
ZAoKCkJ1dCwgY291bGQgSSBkbyB0aGUgc2FtZSB3aXRob3V0IH VzaW5nIGFuIGFsaWFzPyBjb3Vs
ZCBJIGNhbGwgZGlyZWN0bHkKdG8gYSBwYXJlbnQgKEFycmF5KS BtZXRob2QgZnJvbSBhbnkgbWVo
dG9kIG9mIHRoZSAic29vbiIgY2xhc3M/CgotLSAKScOxYWtpIEJheiBDYXN0aWxsbwo8aWJjQGFs
aWF4Lm5ldD4K

 
Reply With Quote
 
 
 
 
Sandro Paganotti
Guest
Posts: n/a
 
      05-06-2008
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).bi nd(self).call
end
end

ClassB.new.method2

On Tue, May 6, 2008 at 9:46 AM, I=F1aki Baz Castillo <(E-Mail Removed)> 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
> <(E-Mail Removed)>
>




--=20
Go outside! The graphics are amazing!

 
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
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
Java EE Developer-HOT HOT OPENINGS Sandy Miller Java 0 01-08-2008 05:06 AM
one hot< two hot in FSM encoding mobi999 VHDL 0 06-09-2007 12:59 AM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
Call child class methods in parent class Martin Herbert Dietze C++ 9 05-04-2005 02:41 PM



Advertisments