From: Robert Klemme Date: 2008-09-11T22:00:39+09:00 Subject: Re: define and call methods in ruby 2008/9/11 Jay Pangmi : > David A. Black wrote: >> This will get you started: >> >> class Myclass >> def method_to_call >> puts "Hello!" >> end >> end >> >> object = Myclass.new >> object.method_to_call >> >> It's the object (the instance of Myclass) that can execute the method. >> >> >> David > > Thanks David for the help, but just kinda suprised, wouldn't it be for > method that's being called from another class (no offense, just my view > from my lil knowledge of java). If what you are saying is what should be > for method calls in the same class then can you please lighten me up a What? > bit coz I'm new to ruby as well. I mean method calls as: > ================================================================================ > class myclass > if something then > do_something > end > > #implementation of do_something method. > def do_something > here something is done.. > end > end You are mixing instance and class methods. When you do class X if expr then do_something end end do_somehing must be a class method because inside class..end self is the class. Try it out: class Foo p self def x p self end end Foo.new.x From what you write I am unsure whether basic OO principles are clear to you. In case not, you should probably read some introductory material about OOA/OOD/OOP. Cheers robert -- use.inject do |as, often| as.you_can - without end