Hot to call to any parent class method?

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

SGksIEkndmUgbW9kaWZpZWQgImRlbGV0ZSIgY2xhc3MgaW4gTXlBcnJheSBjbGFzcyBidXQgaW4g
b3RoZXIgY3VzdG9tCm1ldGhvZCBJIG5lZWQgdG8gY2FsbCB0byBpcmlnaW5hbCAiZGVsZXRlIiBt
ZXRob2QuCldlbGwgSSBrbm93IHRoYXQgSSBjYW4gZG86CgogIGFsaWFzIG9yaWdpbmFsX2RlbGV0
ZSBkZWxldGUKCiBkZWYgZGVsZXRlKHYpCiAgICAgLi4ubXlfc3R1ZmYuLi4KICBlbmQKCiAgZGVm
IG90aGVyX21ldGhvZAogICAgIC4uLgogICAgIG9yaWdpbmFsX2RlbGV0ZSAuLi4KICBlbmQKCmVu
ZAoKCkJ1dCwgY291bGQgSSBkbyB0aGUgc2FtZSB3aXRob3V0IHVzaW5nIGFuIGFsaWFzPyBjb3Vs
ZCBJIGNhbGwgZGlyZWN0bHkKdG8gYSBwYXJlbnQgKEFycmF5KSBtZXRob2QgZnJvbSBhbnkgbWVo
dG9kIG9mIHRoZSAic29vbiIgY2xhc3M/CgotLSAKScOxYWtpIEJheiBDYXN0aWxsbwo8aWJjQGFs
aWF4Lm5ldD4K
 
S

Sandro Paganotti

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

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?



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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top