class Object # Takes a hash and creates (singleton) attr_writers for each key. # # require 'facet/object/with_accessor' # # with_writer { :x => 1, :y => 2 } # @x #=> 1 # @y #=> 2 # self.x = 3 # self.y = 4 # @x #=> 3 # @y #=> 4 # def with_writer(h) (class << self ; self ; end).send( :attr_writer, *h.keys ) h.each { |k,v| instance_variable_set("@#{k}", v) } end end