calling instance method defined in a parent class ??

  • Thread starter Christopher J. Bottaro
  • Start date
C

Christopher J. Bottaro

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.
 
W

widmannm

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.
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top