Class: Twizo::Result
- Inherits:
-
Object
- Object
- Twizo::Result
- Defined in:
- lib/twizo/result.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#add_attribute_accessor(attr_name, attr_value) ⇒ Object
Getter and Setter fields are dynamically created.
-
#add_result(item) ⇒ Object
add an item to parent result.
-
#initialize(result) ⇒ Result
constructor
Constructor.
- #set_fields(fields) ⇒ Object
Constructor Details
#initialize(result) ⇒ Result
Constructor
23 24 25 |
# File 'lib/twizo/result.rb', line 23 def initialize(result) set_fields(result) end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
16 17 18 |
# File 'lib/twizo/result.rb', line 16 def result @result end |
Instance Method Details
#add_attribute_accessor(attr_name, attr_value) ⇒ Object
Getter and Setter fields are dynamically created
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/twizo/result.rb', line 42 def add_attribute_accessor(attr_name, attr_value) self.class.send(:define_method, "#{attr_name}=".to_sym) do |value| instance_variable_set('@' + attr_name.to_s, value) end self.class.send(:define_method, attr_name.to_sym) do instance_variable_get('@' + attr_name.to_s) end self.send("#{attr_name}=".to_sym, attr_value) end |
#add_result(item) ⇒ Object
add an item to parent result
59 60 61 62 |
# File 'lib/twizo/result.rb', line 59 def add_result(item) @result ||= [] @result << item end |
#set_fields(fields) ⇒ Object
30 31 32 33 34 |
# File 'lib/twizo/result.rb', line 30 def set_fields(fields) fields.each do |name, value| add_attribute_accessor(name, value) end end |