# Calling child methods in parent

**URL:** <https://www.ruby-forum.com/t/calling-child-methods-in-parent/102294>\
**Category:** Ruby\
**Created:** [February 8, 2006, 1:56am UTC](https://www.ruby-forum.com/t/calling-child-methods-in-parent/102294 "2006-02-08T01:56:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_Ru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/96bed5/32.png) [@Dave\_Ru](https://www.ruby-forum.com/u/Dave_Ru)\
**Post date:** [February 8, 2006, 1:56am UTC](https://www.ruby-forum.com/t/calling-child-methods-in-parent/102294/1 "2006-02-08T01:56:16Z")

</div>

Hi-  
This may be a pretty easy question but I’m new to ruby

Say I have a class like this

class MyClass

def myCallingMethod  
myMethodToOverrider(“hello”)  
end

def myMethodToOverride(string)

```
end

```

end

and I want to create a chile method like so

class ChildClass \< MyClass  
def myMethodToOverride(string)  
puts string  
end  
end

Then I create an instance of my child class

child = ChildClass.new()

then I call myCallingMethod

child.myCallingMethod()

is there anyway to have the method in the parent object call the  
overriden  
method in the child?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Dave\_Ru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/96bed5/32.png) [@Dave\_Ru](https://www.ruby-forum.com/u/Dave_Ru)\
**Post date:** [February 8, 2006, 3:24am UTC](https://www.ruby-forum.com/t/calling-child-methods-in-parent/102294/2 "2006-02-08T03:24:18Z")

</div>

> is there anyway to have the method in the parent object call the  
> overriden  
> method in the child?

That’s the default behaviour, actually. In C++ terms, all methods  
are virtual.

Observe:

class Parent  
def say\_what  
virtual\_method(“Hello World”)  
end  
def virtual\_method(str)  
“I say: #{str}”  
end  
end

class Child \< Parent  
def virtual\_method(str)  
“My parent says: #{str}”  
end  
end

william = Parent.new  
william.say\_what

# =\> “I say: Hello World”

billy = Child.new  
billy.say\_what

# =\> “My parent says: Hello World”

matthew smillie.
