From: "David A. Black" Date: 2008-09-11T22:36:36+09:00 Subject: Re: define and call methods in ruby Hi -- On Thu, 11 Sep 2008, Jay Pangmi wrote: > 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 > 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're defining do_something as an instance method of Myclass; that means that you need an instance of Myclass in order to call do_something. To get that instance, you need to do Myclass.new. David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL Advancing with Rails January 19-22 Fort Lauderdale, FL * * Co-taught with Patrick Ewing! See http://www.rubypal.com for details and updates!