Method: Object#set_attr_with_readers
- Defined in:
- lib/y_support/core_ext/object/misc.rb
#set_attr_with_readers(hash) ⇒ Object
Assigns prescribed atrributes to the object and makes them accessible with getter (reader) methods. Raises NameError should any of the getters shadow / overwrite existing methods.
10 11 12 13 14 15 |
# File 'lib/y_support/core_ext/object/misc.rb', line 10 def set_attr_with_readers hash hash.each_pair { |ß, value| fail NameError, "Method \##{ß} already defined!" if methods.include? ß set_attr_with_readers! ß => value } end |