Robert Dober wrote:
> On Thu, Sep 11, 2008 at 4:37 PM, Jay Pangmi <jaeezzy / gmail.com> wrote:
>> David A. Black wrote:
>>> 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
>> Thanks again David, So, here's how I've tried:
>>
>> class MyDate
>>  md=MyDate.new()
>>  md.display
>>  def display
>>   puts "hi"
>>  end
>> end
> look at David's original post *again*
> 

Remember that ruby is interpreted, not compiled.  If the interpreter 
hasn't textually seen a method definition yet, it does not exist.
Add to that the fact that display is a base method in ruby to display 
prints the contents of an object here's what happens:

md = MyDate.new()  makes a new object of type MyDate
md.display  Invokes the Object.display method.. but since MyDate has
             no members, there's not much to display

def display ... overrides the Object.display method finally...

Now if you had written:

class MyDate
    def display
      puts "hi"
    end
    md=MyDate.new()
    md.display
  end


Things might be different. Whether you get what you want? That depends 
a lot on what you want.

Ron
-- 
Ron Fox
NSCL
Michigan State University
East Lansing, MI 48824-1321