Module: Liquidscript::ICR::Representable

Extended by:
Forwardable
Includes:
Comparable
Included in:
Compiler::ICR::Heredoc, Code, Context, Set, Variable, Scanner::Token
Defined in:
lib/liquidscript/icr/representable.rb

Overview

Used to show that a specific element of the ICR is representable as an array. It will forward the methods #to_s and #inspect to the #to_a method, expecting the including module to define it.

Instance Method Summary collapse

Instance Method Details

#to_a!Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/liquidscript/icr/representable.rb', line 27

def to_a!
  do_map = proc do |e|
    if e.is_a?(Representable)
      e.to_a!
    elsif e.is_a? Array
      e.map(&do_map)
    else
      e
    end
  end

  to_a.map(&do_map)
end

#to_aryObject



15
16
17
# File 'lib/liquidscript/icr/representable.rb', line 15

def to_ary
  to_a
end

#to_sexpObject



23
24
25
# File 'lib/liquidscript/icr/representable.rb', line 23

def to_sexp
  Sexp.new(self)
end

#to_yamlObject



19
20
21
# File 'lib/liquidscript/icr/representable.rb', line 19

def to_yaml
  to_a!.to_yaml
end