Module: FinerStruct::Named
- Defined in:
- lib/finer_struct/named.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.build_class(attribute_names, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/finer_struct/named.rb', line 14 def self.build_class(attribute_names, &block) Class.new do define_method(:attribute_names, -> { attribute_names }) include Named class_eval(&block) end end |
Instance Method Details
#initialize(attributes = {}) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/finer_struct/named.rb', line 5 def initialize(attributes = {}) attributes.each_pair do |name, value| unless attribute_names.include?(name) raise(ArgumentError, "no such attribute: #{name}") end instance_variable_set("@#{name}", value) end end |