Method: Kernel#attr_singleton_writer

Defined in:
lib/core/facets/kernel/attr_singleton.rb

#attr_singleton_writer(*args) ⇒ Object

Create singleton attr_writers.

obj = Object.new

obj.attr_singleton_writer :x, :y

obj.x = 3
obj.y = 4

CREDIT: Trans



31
32
33
34
35
36
# File 'lib/core/facets/kernel/attr_singleton.rb', line 31

def attr_singleton_writer(*args)
  #h, a = *args.partition{|a| Hash===a}
  (class << self ; self ; end).send( :attr_writer, *args )
  #(class << self ; self ; end).send( :attr_writer, *h.keys )
  #h.each { |k,v| instance_variable_set("@#{k}", v) }
end