Class: Liquidscript::ICR::Code
- Inherits:
-
Object
- Object
- Liquidscript::ICR::Code
- Includes:
- Representable
- Defined in:
- lib/liquidscript/icr/code.rb
Overview
An individual code point. This is normally in a set. A code will have an action, and arguments that accompany that action. The arguments list can be however long.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#action ⇒ Symbol
(also: #type)
readonly
The action that this code is associated with.
-
#arguments ⇒ Array
readonly
The arguments that are used for this action.
Instance Method Summary collapse
-
#initialize(action, *arguments) ⇒ Code
constructor
Initializes the code.
-
#method_missing(method, *args, &block) ⇒ Object
Send the method to @arguments if it doesn’t exist here.
-
#respond_to_missing?(method, include_private = false) ⇒ Boolean
If we don’t respond to it, the @arguments array might.
-
#to_a ⇒ Array
Turns the code into an array, containing the action and the arguments.
Methods included from Representable
Constructor Details
#initialize(action, *arguments) ⇒ Code
Initializes the code. It takes an action and an argument as its arguments. The action should not change from this point forward.
32 33 34 35 |
# File 'lib/liquidscript/icr/code.rb', line 32 def initialize(action, *arguments) @action = action @arguments = arguments end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Send the method to @arguments if it doesn’t exist here.
62 63 64 |
# File 'lib/liquidscript/icr/code.rb', line 62 def method_missing(method, *args, &block) @arguments.public_send(method, *args, &block) end |
Instance Attribute Details
#action ⇒ Symbol (readonly) Also known as: type
The action that this code is associated with. This should be a symbol.
14 15 16 |
# File 'lib/liquidscript/icr/code.rb', line 14 def action @action end |
#arguments ⇒ Array (readonly)
The arguments that are used for this action. This is an array.
20 21 22 |
# File 'lib/liquidscript/icr/code.rb', line 20 def arguments @arguments end |
Instance Method Details
#respond_to_missing?(method, include_private = false) ⇒ Boolean
If we don’t respond to it, the @arguments array might. Ask them if they do, and if they don’t, respond accordingly.
54 55 56 |
# File 'lib/liquidscript/icr/code.rb', line 54 def respond_to_missing?(method, include_private = false) @arguments.respond_to?(method) end |
#to_a ⇒ Array
Turns the code into an array, containing the action and the arguments. Note that changing this array will not change the code.
42 43 44 |
# File 'lib/liquidscript/icr/code.rb', line 42 def to_a [@action, *@arguments] end |