Class: Caseable
- Inherits:
-
Object
- Object
- Caseable
- Defined in:
- lib/cases/caseable.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Class Method Summary collapse
Instance Method Summary collapse
- #execute(original_result, &block) ⇒ Object
-
#initialize(object) ⇒ Caseable
constructor
A new instance of Caseable.
- #method_missing(method, &block) ⇒ Object
Constructor Details
#initialize(object) ⇒ Caseable
Returns a new instance of Caseable.
8 9 10 |
# File 'lib/cases/caseable.rb', line 8 def initialize(object) @object = object end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, &block) ⇒ Object
17 18 19 20 |
# File 'lib/cases/caseable.rb', line 17 def method_missing(method, &block) case_blocks << block if object.send(method) case_blocks end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
2 3 4 |
# File 'lib/cases/caseable.rb', line 2 def object @object end |
Class Method Details
.execute(result, &block) ⇒ Object
4 5 6 |
# File 'lib/cases/caseable.rb', line 4 def self.execute(result, &block) new(result).execute(result, &block) end |
Instance Method Details
#execute(original_result, &block) ⇒ Object
12 13 14 15 |
# File 'lib/cases/caseable.rb', line 12 def execute(original_result, &block) block.call(self) case_blocks.reduce(original_result) { |result, case_block| case_block.call(result) } end |