# Inheritance

**URL:** <https://www.ruby-forum.com/t/inheritance/129202>\
**Category:** Ruby\
**Created:** [February 15, 2008, 11:58am UTC](https://www.ruby-forum.com/t/inheritance/129202 "2008-02-15T11:58:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![veovis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c89c15/32.png) [@veovis](https://www.ruby-forum.com/u/veovis)\
**Post date:** [February 15, 2008, 11:58am UTC](https://www.ruby-forum.com/t/inheritance/129202/1 "2008-02-15T11:58:43Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![veovis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c89c15/32.png) [@veovis](https://www.ruby-forum.com/u/veovis)\
**Post date:** [February 15, 2008, 12:09pm UTC](https://www.ruby-forum.com/t/inheritance/129202/2 "2008-02-15T12:09:33Z")

</div>

Mickael Veovis wrote:

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

---

<div class="post-metadata">

**Author:** ![veovis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c89c15/32.png) [@veovis](https://www.ruby-forum.com/u/veovis)\
**Post date:** [February 15, 2008, 12:10pm UTC](https://www.ruby-forum.com/t/inheritance/129202/3 "2008-02-15T12:10:44Z")

</div>

class B \< A  
def tata  
toto  
end  
end

Kind regards,  
Nicolai

---

<div class="post-metadata">

**Author:** ![veovis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c89c15/32.png) [@veovis](https://www.ruby-forum.com/u/veovis)\
**Post date:** [February 15, 2008, 12:13pm UTC](https://www.ruby-forum.com/t/inheritance/129202/4 "2008-02-15T12:13:40Z")

</div>

I wrote:

> 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

---

<div class="post-metadata">

**Author:** ![veovis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c89c15/32.png) [@veovis](https://www.ruby-forum.com/u/veovis)\
**Post date:** [February 15, 2008, 2:18pm UTC](https://www.ruby-forum.com/t/inheritance/129202/5 "2008-02-15T14:18:48Z")

</div>

Mickael Rouvier wrote:

> Â end
> 
> Â def tata
> 
> Â 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

---

<div class="post-metadata">

**Author:** ![veovis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c89c15/32.png) [@veovis](https://www.ruby-forum.com/u/veovis)\
**Post date:** [February 15, 2008, 12:18pm UTC](https://www.ruby-forum.com/t/inheritance/129202/6 "2008-02-15T12:18:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![veovis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c89c15/32.png) [@veovis](https://www.ruby-forum.com/u/veovis)\
**Post date:** [February 15, 2008, 2:31pm UTC](https://www.ruby-forum.com/t/inheritance/129202/7 "2008-02-15T14:31:50Z")

</div>

On 15.02.2008, at 14:17, Sebastian H. wrote:

> > ```
> > puts "mmmmm"
> > 
> > ```
> > 
> > end
> > 
> > def tata
> > 
> > end  
> > end
> > 
> > And I would like in B.tata to call the method toto of A.

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

---

<div class="post-metadata">

**Author:** ![veovis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/c89c15/32.png) [@veovis](https://www.ruby-forum.com/u/veovis)\
**Post date:** [February 15, 2008, 2:34pm UTC](https://www.ruby-forum.com/t/inheritance/129202/8 "2008-02-15T14:34:46Z")

</div>

On 15.02.2008, at 14:30, Karl-Heinz Wild wrote:

> > > class B \< A
> 
> end  
> def tata  
> totoo  
> end

> end
> 
> b = B.new  
> b.toto  
> b.totoo

Ups. 🙂

Karl-Heinz
