Class: Liquidscript::ICR::Code

Inherits:
Object
  • Object
show all
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

Set

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Representable

#to_a!, #to_ary, #to_yaml

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.

Parameters:

  • action (Symbol)
  • arguments (Array)


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.

Returns:

  • (Object)


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

#actionSymbol (readonly) Also known as: type

The action that this code is associated with. This should be a symbol.

Returns:

  • (Symbol)


14
15
16
# File 'lib/liquidscript/icr/code.rb', line 14

def action
  @action
end

#argumentsArray (readonly)

The arguments that are used for this action. This is an array.

Returns:



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.

Parameters:

  • method (Symbol)

    the method to check.

  • include_private (Boolean) (defaults to: false)

    whether or not to include private methods.

Returns:

  • (Boolean)


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_aArray

Turns the code into an array, containing the action and the arguments. Note that changing this array will not change the code.

Returns:



42
43
44
# File 'lib/liquidscript/icr/code.rb', line 42

def to_a
  [@action, *@arguments]
end