From: Dominik Bathon Date: 2005-04-10T02:46:24+09:00 Subject: Re: [curiousity] why aren't declarations just syntactic sugar? On Fri, 08 Apr 2005 07:24:54 +0200, Jon Raphaelson wrote: > Curt Sampson wrote: > >> For example: explain the results of these two programs to me: >> ---------- >> def do_me_harder >> puts "Oh yes!" >> end >> puts do_me_harder >> ---------- >> module Foo >> def do_me_harder >> puts "Oh yes!" >> end >> puts do_me_harder >> end >> ---------- >> cjs > > Both of those will produce the output > > Oh yes! > nil No, they won't ;-) The 2nd will raise an exception: NameError: undefined local variable or method `do_me_harder' for Foo:Module do_me_harder is an instance method (you can only call it on an instance of a class including Foo): class A include Foo end A.new.do_me_harder But the following would work: module Foo def Foo.do_me_harder puts "Oh yes!" end puts do_me_harder end In this case do_me_harder is a singleton method of module Foo. HTH, Dominik