Parent class cannot call child class method

Hi guys,

I have the following design which is not working as I would like it
to:

class A
def bar
raise “Base class can’t do bar!”
end

def foo
bar
end
end

class B < A
def bar
puts “B doing bar”
end

def foo
puts “B does this first”
super
end
end

If I do B.new.foo I get an exception because Base class can’t do bar
which is understandable. However, I want B#bar to be called. What
would be the proper way to solve this problem?

Thanks in advance,
Edgardo

Alle Friday 18 January 2008, Ed Hames ha scritto:

def foo
puts “B does this first”
super
end
end

If I do B.new.foo I get an exception because Base class can’t do bar
which is understandable. However, I want B#bar to be called. What
would be the proper way to solve this problem?

Thanks in advance,
Edgardo

It works for me. Are you sure this is the exact code you’re running?

Stefano

On Jan 18, 4:21 pm, Stefano C. [email protected] wrote:

def bar
puts “B doing bar”
would be the proper way to solve this problem?

Thanks in advance,
Edgardo

It works for me. Are you sure this is the exact code you’re running?

I actually forgot to write the B#bar method in my program :frowning:

Sorry about that,
Edgardo