From: David Alan Black Date: 2001-11-18T14:06:40+09:00 Subject: [ruby-talk:25741] Re: Parametric classes Hello -- On Sun, 18 Nov 2001, Hal E. Fulton wrote: > The confusing part is passing in the > parent class to Class.new -- this is > a parameter to the initialize method, > but it's not used in my code. What I think is happening is this: When you do: > Australian = Class.new(Nationality) do > @@native_lang = "English" > end Class.new handles the call, creating a class which is a child of Nationality. It then hands its arguments off to Class#initialize. At that point, #initialize does receive the parent argument, but doesn't do anything with it (because its status as superclass has already been assured by Class.new). Is that what you were asking about, and is that explanation reasonable? (or even correct? :-) > class Nationality > > def Nationality.native_lang > class_eval("@@native_lang") > end > > def Nationality.native_lang=(x) > class_eval("@@native_lang = #{x}") > end > > #... > > end That might be a good place for the idiom Guy D. was showing someone earlier: class Nationality class << self attr_accessor :native_lang end end which lets you use instance vars instead of class vars: Australian = Class.new(Nationality) do @native_lang = "English" end (if that's appropriate for what you're doing). David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav