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.