From: Timothy Goddard Date: 2006-01-25T00:37:56+09:00 Subject: Re: class methods like attr: Here's a quick hack. There are probably better ways. def self.var_with_default(variable, default) @@current_default = default class_eval <<-END_BLOCK @@default_#{variable.to_s} = @@current_default attr_writer #{variable.to_s} def #{variable.to_s} @#{variable.to_s} || @@default_#{variable.to_s} end END_BLOCK end Include that in the class it will be used in (or an ancestor). This method is not thread safe.