Module: Class2::StrictConstructor
- Defined in:
- lib/class2.rb
Overview
By default unknown arguments are ignored. <code>include<code>ing this will cause an ArgumentError to be raised if an attribute is unknown.
Class Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/class2.rb', line 275 def self.included(klass) klass.class_eval do def initialize(attributes = nil) return unless __initialize(attributes) attributes.each do |name, _| next if self.class.__attributes.include?(name.respond_to?(:to_sym) ? name.to_sym : name) raise ArgumentError, "unknown attribute: #{name}" end end end end |