require 'yaml' %w( . lib ../lib ).each{|d| $:.unshift d} require 'attributes' class AbstractThingy class_attributes %w( size color width height ) attributes %w( size color width height ) def initialize opts = {} klass.reader_attributes.each{|key| send(key, opts[key] || default(key))} end def default name klass.send name end def klass self.class end def inspect klass.reader_attributes.inject({}){|h, key| h[key] = send key; h}.to_yaml end end class Thingy < AbstractThingy size 42 color 'pinky-purple' width 42.0 height 42.0 end ti = Thingy::new 'color' => 'bluish-brown' p ti Thingy::size 420 ti = Thingy::new p ti