# Method not inherit?

**URL:** <https://www.ruby-forum.com/t/method-not-inherit/194762>\
**Category:** Ruby\
**Created:** [September 10, 2010, 1:22am UTC](https://www.ruby-forum.com/t/method-not-inherit/194762 "2010-09-10T01:22:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zoopzoop](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/59ef9b/32.png) [@zoopzoop](https://www.ruby-forum.com/u/zoopzoop)\
**Post date:** [September 10, 2010, 1:22am UTC](https://www.ruby-forum.com/t/method-not-inherit/194762/1 "2010-09-10T01:22:39Z")

</div>

Hi,

I’m a newbie in Ruby and created this module:

require ‘couchrest\_model’  
module RdfModelModule

class RdfModel \< CouchRest::Model::Base  
def rdf\_schema  
p ‘hello’  
end  
end

end

When I create a new class based no this class like this:

require ‘rdfmodelmodule’  
class Mine \< RdfModelModule::RdfModel  
rdf\_schema  
end

I’m getting this error:  
NoMethodError: undefined method `rdf\_schema’ for Mine:Class

This is a bit confusing! Why is rdf\_schema not inherit by the ‘Mine’  
class??

Cheers,  
Manuel

---

<div class="post-metadata">

**Author:** ![zoopzoop](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/59ef9b/32.png) [@zoopzoop](https://www.ruby-forum.com/u/zoopzoop)\
**Post date:** [September 10, 2010, 2:06am UTC](https://www.ruby-forum.com/t/method-not-inherit/194762/2 "2010-09-10T02:06:11Z")

</div>

Hello,

That method is inherited, but only instances can use it:

require ‘rdfmodelmodule’  
class Mine \< RdfModelModule::RdfModel  
def something\_else  
self.rdf\_schema  
end  
end

# This works

Mine.new.rdf\_schema  
Mine.new.something\_else

Daniel GaytÃ¡n  
[http://survey.richapplabs.com/index.php?sid=62661&lang=en](http://survey.richapplabs.com/index.php?sid=62661&lang=en)

2010/9/9 Manuel M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![zoopzoop](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/59ef9b/32.png) [@zoopzoop](https://www.ruby-forum.com/u/zoopzoop)\
**Post date:** [September 10, 2010, 2:09am UTC](https://www.ruby-forum.com/t/method-not-inherit/194762/3 "2010-09-10T02:09:06Z")

</div>

Hi.

On Thu, Sep 9, 2010 at 6:23 PM, Manuel M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> end  
> end
> 
> I’m getting this error:  
> NoMethodError: undefined method `rdf\_schema’ for Mine:Class
> 
> This is a bit confusing! Why is rdf\_schema not inherit by the ‘Mine’  
> class??

It’s because you are sending the “rdf\_schema” message (trying to  
invoke the method) on the _class_ Mine. When you right code in a class  
definition that isn’t part of a method, as you did, that code is  
executed in the context of the class; i.e. any methods you invoke will  
be sent to the class object, instead of an instance of that class.  
rdf\_schema is an instance method, so you need an instance of Mine to  
invoke it.

You could make rdf\_schema a class method, and then your code would work:

class RdfModel \< CouchRest::Model::Base  
def self.rdf\_schema # note “self.”  
p ‘hello’  
end  
end

I’m not sure if that’s what you want your code to do, though. The  
other way would be to change the code in Mine so that it’s inside an  
instance method, as Daniel G. wrote.
