Class: ResourceController::ResponseCollector
- Inherits:
-
Object
- Object
- ResourceController::ResponseCollector
- Defined in:
- lib/resource_controller/response_collector.rb
Instance Attribute Summary collapse
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
Instance Method Summary collapse
- #[](symbol) ⇒ Object
- #dup ⇒ Object
-
#initialize ⇒ ResponseCollector
constructor
A new instance of ResponseCollector.
- #method_missing(method_name, &block) ⇒ Object
Constructor Details
#initialize ⇒ ResponseCollector
Returns a new instance of ResponseCollector.
8 9 10 |
# File 'lib/resource_controller/response_collector.rb', line 8 def initialize @responses = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, &block) ⇒ Object
12 13 14 15 |
# File 'lib/resource_controller/response_collector.rb', line 12 def method_missing(method_name, &block) @responses.delete self[method_name] @responses << [method_name, block || nil] end |
Instance Attribute Details
#responses ⇒ Object (readonly)
Returns the value of attribute responses.
4 5 6 |
# File 'lib/resource_controller/response_collector.rb', line 4 def responses @responses end |
Instance Method Details
#[](symbol) ⇒ Object
17 18 19 |
# File 'lib/resource_controller/response_collector.rb', line 17 def [](symbol) @responses.find { |method, block| method == symbol } end |
#dup ⇒ Object
21 22 23 24 25 |
# File 'lib/resource_controller/response_collector.rb', line 21 def dup returning ResponseCollector.new do |duplicate| duplicate.instance_variable_set(:@responses, responses.dup) end end |