Sha256: 5496961f50dad29a175310c9e801db3686f1113fad39b96627e7b354a858eddd

Contents?: true

Size: 463 Bytes

Versions: 3

Compression:

Stored size: 463 Bytes

Contents

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facets-0.7.0 lib/facet/object/with_accessor.rb
facets-0.7.1 lib/facet/object/with_accessor.rb
facets-0.7.2 lib/facet/object/with_accessor.rb