Module: Changi::FlexibleAttributes::ClassMethods
- Defined in:
- lib/changi/flexible_attributes.rb
Instance Method Summary collapse
- #attribute_names ⇒ Object
- #attributes ⇒ Object
- #define_attribute(name, reader: Reader::StringReader, opts: {}, &block) ⇒ Object
Instance Method Details
#attribute_names ⇒ Object
8 9 10 |
# File 'lib/changi/flexible_attributes.rb', line 8 def attribute_names attributes.map { |x| x[:name] } end |
#attributes ⇒ Object
4 5 6 |
# File 'lib/changi/flexible_attributes.rb', line 4 def attributes @attributes ||= [] end |
#define_attribute(name, reader: Reader::StringReader, opts: {}, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/changi/flexible_attributes.rb', line 12 def define_attribute name, reader: Reader::StringReader, opts: {}, &block attr_accessor name.to_sym attributes << { name: name, reader: (block_given? ? block : ->(*args) { reader.new.read(*args) }), opts: opts } end |