Class: Bound::BoundClass
- Inherits:
-
Object
- Object
- Bound::BoundClass
- Defined in:
- lib/bound.rb
Class Attribute Summary collapse
-
.attributes ⇒ Object
Returns the value of attribute attributes.
-
.optionals ⇒ Object
Returns the value of attribute optionals.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash_or_object) ⇒ BoundClass
constructor
A new instance of BoundClass.
- #method_missing(meth, *args, &blk) ⇒ Object
Constructor Details
#initialize(hash_or_object) ⇒ BoundClass
41 42 43 44 45 |
# File 'lib/bound.rb', line 41 def initialize(hash_or_object) build_hash(hash_or_object) validate! seed end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
47 48 49 50 |
# File 'lib/bound.rb', line 47 def method_missing(meth, *args, &blk) attribute = meth.to_s.gsub(/=$/, '') raise ArgumentError.new("Unknown attribute: #{attribute}") end |
Class Attribute Details
.attributes ⇒ Object
Returns the value of attribute attributes.
18 19 20 |
# File 'lib/bound.rb', line 18 def attributes @attributes end |
.optionals ⇒ Object
Returns the value of attribute optionals.
18 19 20 |
# File 'lib/bound.rb', line 18 def optionals @optionals end |
Class Method Details
.extract_optionals(attributes) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/bound.rb', line 32 def extract_optionals(attributes) if attributes.last.kind_of? Hash attributes.pop[:optional] else [] end end |
.set_attributes(*attributes) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bound.rb', line 20 def set_attributes(*attributes) attributes = attributes.dup optionals = extract_optionals(attributes) self.optionals = optionals attr_accessor(*optionals) self.attributes = attributes attr_accessor(*attributes) end |