Class: Hyraft::Circuit
- Inherits:
-
Object
- Object
- Hyraft::Circuit
- Defined in:
- lib/hyraft/engine/circuit.rb
Instance Method Summary collapse
- #execute(input = {}) ⇒ Object
-
#initialize(ports = {}) ⇒ Circuit
constructor
A new instance of Circuit.
-
#method_missing(method, *args, &block) ⇒ Object
Magic: Automatically route custom methods to execute.
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(ports = {}) ⇒ Circuit
Returns a new instance of Circuit.
5 6 7 |
# File 'lib/hyraft/engine/circuit.rb', line 5 def initialize(ports = {}) @ports = ports end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Magic: Automatically route custom methods to execute
10 11 12 13 14 15 16 |
# File 'lib/hyraft/engine/circuit.rb', line 10 def method_missing(method, *args, &block) if respond_to_missing?(method) execute(operation: method, params: args.first || {}) else super end end |
Instance Method Details
#execute(input = {}) ⇒ Object
24 25 26 |
# File 'lib/hyraft/engine/circuit.rb', line 24 def execute(input = {}) raise NotImplementedError, "Circuits must implement execute method" end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
18 19 20 21 22 |
# File 'lib/hyraft/engine/circuit.rb', line 18 def respond_to_missing?(method, include_private = false) # Check if it's a public method defined in the subclass OR # if the execute method can handle it self.class.public_method_defined?(method) || can_handle_operation?(method) end |