Module: FinerStruct::Named
- Defined in:
- lib/finer_struct/named.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.build_class(superclass, attribute_names, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/finer_struct/named.rb', line 13 def self.build_class(superclass, attribute_names, &block) Class.new(superclass) do include Named define_method(:attribute_names, -> { attribute_names }) attribute_names.each do |name| define_method(name) { @attributes[name] } end class_eval(&block) if block_given? end end |
Instance Method Details
#initialize(attributes = {}) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/finer_struct/named.rb', line 4 def initialize(attributes = {}) unknown_attributes = attributes.keys - attribute_names unless unknown_attributes.empty? raise(ArgumentError, "unknown attributes: #{unknown_attributes.join(', ')}") end super end |