[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

calling instance method defined in a parent class ??

Christopher J. Bottaro

9/27/2007 12:17:00 AM

How do I do that? Consider the following class definitions:

class Foo
def a
puts "Foo"
end
end

class Bar < Foo
def a
puts "Bar"
end
def b
parent.a # I want to call Foo#a here for this instance of Bar.
end
end

Bar.new.b # => "Foo"

Thanks for the help.


1 Answer

widmannm

9/27/2007 1:04:00 AM

0

On Sep 26, 5:16 pm, "Christopher J. Bottaro" <cjbott...@gmail.com>
wrote:
> How do I do that? Consider the following class definitions:

class Foo
def a
puts 'foo'
end
end

class Bar < Foo
alias b a

def a
puts 'bar'
end
end

Foo.new.a # => foo
Bar.new.a # => bar
Bar.new.b # => foo

> class Foo
> def a
> puts "Foo"
> end
> end
>
> class Bar < Foo
> def a
> puts "Bar"
> end
> def b
> parent.a # I want to call Foo#a here for this instance of Bar.
> end
> end
>
> Bar.new.b # => "Foo"
>
> Thanks for the help.

No problem.