Class: Boxxspring::Abstract
- Inherits:
-
Object
- Object
- Boxxspring::Abstract
show all
- Defined in:
- lib/boxxspring/abstract.rb
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}) ⇒ Abstract
Returns a new instance of Abstract.
5
6
7
8
9
10
|
# File 'lib/boxxspring/abstract.rb', line 5
def initialize( attributes = {} )
@attributes = {}
attributes.each_pair do | key, value |
self.send( key, value )
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/boxxspring/abstract.rb', line 20
def method_missing( method, *arguments, &block )
result = nil
if arguments.length == 0
result = @attributes[ method.to_sym ]
if result.nil?
result = Abstract.new
result.instance_eval( &block ) unless block.nil?
@attributes[ method.to_sym ] = result
end
elsif arguments.length == 1
method = method.to_s.gsub( /=$/, '' )
result = arguments[ 0 ]
@attributes[ method.to_sym ] = result
else
result = super
end
result
end
|
Instance Method Details
#include?(name) ⇒ Boolean
16
17
18
|
# File 'lib/boxxspring/abstract.rb', line 16
def include?( name )
@attributes.include?( name )
end
|
#to_hash ⇒ Object
12
13
14
|
# File 'lib/boxxspring/abstract.rb', line 12
def to_hash
return @attributes
end
|