From: dblack@... Date: 2006-10-03T22:07:26+09:00 Subject: Re: Newbie: Question => How to do this with Classes ? Hi -- On Tue, 3 Oct 2006, Eye Matz wrote: > class Important > def set_this_value_method(value) > end > end > > class SemiImportant < Important > set_this_value_method :something_or_anything > end > > Could some kind sould please, please take the time to explain the > fundamentals of Ruby's class/module functionality in regards to the > above example. In the second snippet, you're sending the message "set_this_value_method" to the class object SemiImportant. In order for that object to understand the message, a method called set_this_value_method has to be defined either in 1. the object's class (which, in this case, is actually Class 2. on a singleton (per-object) basis for the object 3. on a singleton basis in the object's super[super[super...]]class. So, you could do this: class Important def self.set_this_value_method(value) # note the 'self' end end class SemiImportant < Important set_this_value_method :x end David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org