# Undefined method error

**URL:** <https://www.ruby-forum.com/t/undefined-method-error/61041>\
**Category:** Ruby\
**Created:** [May 19, 2006, 4:26pm UTC](https://www.ruby-forum.com/t/undefined-method-error/61041 "2006-05-19T16:26:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [May 19, 2006, 4:26pm UTC](https://www.ruby-forum.com/t/undefined-method-error/61041/1 "2006-05-19T16:26:27Z")

</div>

Still trying to get my head wrapped around the concepts regarding  
Modules, Classes and their methods.

Once an instance of the MyErrorLogger::ErrorLogger class has been  
instanciated, shouldn’t Komodo be displaying the intellisense for the  
object? Using the example below, when I type “errorLogger.”, why isn’t a  
list of the properties and methods of the object displayed?

Back on topic, consider the following…

#-- myErrorLogger.rb  
module MyErrorLogger

class ErrorLogger

```
def initialize()
  puts "Instance of MyErrorLogger::ErrorLogger has been created"
end

def ErrorLogger.PostError(ex)
  puts "Exception error message: " + ex.to_s
end

```

end # class ErrorLogger

end # module MyErrorLogger

#-- testErrorLogger.rb  
require ‘myErrorLogger’  
include MyErrorLogger

def testBed

#-- message is displayed in console window as expected  
errorLogger = MyErrorLogger::ErrorLogger.new

#-- “undefined method ‘PostError’” error gets thrown on this line  
errorLogger.PostError(Exception.new(“test error message”))

end

#-- fire it up  
testBed

---

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [May 19, 2006, 4:59pm UTC](https://www.ruby-forum.com/t/undefined-method-error/61041/2 "2006-05-19T16:59:14Z")

</div>

2006/5/19, Patrick S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> #-- myErrorLogger.rb  
> end  
> def testBed
> 
> #-- message is displayed in console window as expected  
> errorLogger = MyErrorLogger::ErrorLogger.new
> 
> #-- “undefined method ‘PostError’” error gets thrown on this line  
> errorLogger.PostError(Exception.new(“test error message”))

PostError is a method of MyErrorLogger::ErrorLogger, i.e. of the class  
instance. errorLogger is an instance of MyErrorLogger::ErrorLogger so  
it cannot know this method.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [May 19, 2006, 6:22pm UTC](https://www.ruby-forum.com/t/undefined-method-error/61041/3 "2006-05-19T18:22:35Z")

</div>

Robert K. wrote:

> PostError is a method of MyErrorLogger::ErrorLogger, i.e. of the class  
> instance. errorLogger is an instance of MyErrorLogger::ErrorLogger so  
> it cannot know this method.
> 
> Kind regards
> 
> robert

I understood that when an instance of a Method::Class has been created,  
the resulting object would inherit all the methods and properties it was  
based on. Now I’m confused!

---

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [May 19, 2006, 6:38pm UTC](https://www.ruby-forum.com/t/undefined-method-error/61041/4 "2006-05-19T18:38:56Z")

</div>

2006/5/19, Patrick S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> the resulting object would inherit all the methods and properties it was  
> based on. Now I’m confused!

It seems so. What is a “Method::Class” in your terminology?

Ok, I try again. All classes are objects but not all objects are  
classes. A class defines instance methods. These methods can be used  
in instances of the class and instances of sub classes. Every object  
can also have singleton methods (there are other names for them as  
well but I’ll stick with the convention Matz has founded); singleton  
methods are present in that single instance only, there is no  
inheritance associated with them whatsoever but you can find them in  
the singleton class (every object has one and the singleton class has  
only one instance). Since a class is an object it can have singleton  
methods. These do roughly the same as static methods in Java, i.e. the  
operate on the class level. Some code:

irb(main):001:0\> class Foo  
irb(main):002:1\> def bar() # instance method  
irb(main):003:2\> “bar”  
irb(main):004:2\> end  
irb(main):005:1\> end  
=\> nil  
irb(main):006:0\> Foo.new.bar  
=\> “bar”  
irb(main):007:0\> Foo.bar  
NoMethodError: undefined method `bar' for Foo:Class from (irb):7 from :0 irb(main):008:0> f=Foo.new => #<Foo:0x3d0238> irb(main):009:0> f.bar => "bar" irb(main):010:0> def f.special() # singleton method irb(main):011:1> "buh!" irb(main):012:1> end => nil irb(main):013:0> f.special => "buh!" irb(main):014:0> Foo.new.special NoMethodError: undefined method `special’ for #Foo:0x3b5b38  
from (irb):14  
from :0  
irb(main):015:0\> def Foo.nana() # singleton method  
irb(main):016:1\> “nana”  
irb(main):017:1\> end  
=\> nil  
irb(main):018:0\> Foo.nana  
=\> “nana”  
irb(main):019:0\> Foo.new.nana  
NoMethodError: undefined method `nana’ for #Foo:0x3a8ff8  
from (irb):19  
from :0

Hope it helps…

robert

---

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [May 19, 2006, 7:08pm UTC](https://www.ruby-forum.com/t/undefined-method-error/61041/5 "2006-05-19T19:08:38Z")

</div>

Robert K. wrote:

> 2006/5/19, Patrick S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > the resulting object would inherit all the methods and properties it was  
> > based on. Now I’m confused!
> 
> It seems so. What is a “Method::Class” in your terminology?

Oops, I meant “Module::Class”. As for your reply, thanks! I need some  
time to digest it.
