Inheritance

M

Mickael Veovis

Hello,

I have this class :

class A
def toto
puts "tttt"
end
end


class B < A
def tata

end
end

I would like to now how in B.tata I can invoke, I can call the method
toto of A.

Thanks for your reply....
 
J

Jari Williamsson

Mickael said:
Hello,

I have this class :

class A
def toto
puts "tttt"
end
end


class B < A
def tata

end
end

I would like to now how in B.tata I can invoke, I can call the method
toto of A.

Thanks for your reply....

If I understand your question correctly:

b = B.new
b.toto

or:

B.new.toto


Best regards,

Jari Williamsson
 
C

Codeblogger

[Note: parts of this message were removed to make it a legal post.]

class B < A
def tata
toto
end
end

Kind regards,
Nicolai
 
J

Jari Williamsson

I said:
If I understand your question correctly:

Well, I probably misunderstood your it the first time around ;-)

Here's probably what you were looking for:

class B < A
def tata
toto
end
end

and then:

b = B.new
b.tata

or:

B.new.tata
 
M

Mickael Rouvier

Sorry, but I make a mistake my class are :

class A
def toto
puts "tttt"
end
end


class B < A
def toto
puts "mmmmm"
end

def tata

end
end

And I would like in B.tata to call the method toto of A.
 
S

Sebastian Hungerecker

Mickael said:
class A
=C2=A0def toto
=C2=A0 =C2=A0 puts "tttt"
=C2=A0end
end


class B < A
=C2=A0 def toto
=C2=A0 =C2=A0 =C2=A0puts "mmmmm"
=C2=A0 end

=C2=A0 def tata

=C2=A0 end
end

And I would like in B.tata to call the method toto of A.

def tata
A.instance_method:)toto).bind(self).call
end

HTH,
Sebastian
=2D-=20
Jabber: (e-mail address removed)
ICQ: 205544826
 
K

Karl-Heinz Wild

class A
def toto
puts "tttt"
end
end

class B < A
alias :totoo :toto
def toto
puts "mmmm"
end
end

b = B.new
b.toto
b.totoo

- Karl-Heinz
 

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
474,283
Messages
2,571,407
Members
48,101
Latest member
LinetteDeg

Latest Threads

Top