Method: Kernel#onetime_attr_writer
- Defined in:
- lib/platanus/onetime.rb
#onetime_attr_writer(_name) ⇒ Object
Creates a one time writer method.
A one time writer is undefined after the first time it is used.
-
Args :
-
_name-> Attribute name.
-
14 15 16 17 18 19 20 21 22 |
# File 'lib/platanus/onetime.rb', line 14 def onetime_attr_writer(_name) define_method _name.to_s + '=' do |_value| instance_variable_set('@' + _name.to_s, _value) # Unset method by modifying singleton class. = (class << self; self; end) .send(:undef_method,_name.to_s + '=') _value end end |