Class: Porolog::Tail

Inherits:
Object show all
Defined in:
lib/porolog/tail.rb

Overview

A Porolog::Tail is used to represent the tail of a list.

It corresponds to the use of the splat operator within an Array.

Author:

  • Luis Esteban

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = UNKNOWN_TAIL) ⇒ Tail

Creates a new Tail for an Array.

Parameters:

  • value (Object) (defaults to: UNKNOWN_TAIL) —

    the value of the tail.



22
23
24
# File 'lib/porolog/tail.rb', line 22

def initialize(value = UNKNOWN_TAIL)
  @value = value
end

Instance Attribute Details

#value ⇒ Object

Returns the value of the Tail. The optional arguments are ignored; this is for polymorphic compatibility with Porolog::Value and Porolog::Variable, which are used to prevent inifinite recursion.

Returns:

  • (Object) —

    the value of the Tail.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/porolog/tail.rb', line 18

class Tail
  
  # Creates a new Tail for an Array.
  # @param value [Object] the value of the tail.
  def initialize(value = UNKNOWN_TAIL)
    @value = value
  end
  
  # @return [Symbol] the type of the Tail, which should be :tail.
  def type
    :tail
  end
  
  # Returns the value of the Tail.
  # The optional arguments are ignored; this is for polymorphic compatibility with Porolog::Value and Porolog::Variable,
  # which are used to prevent inifinite recursion.
  # @return [Object] the value of the Tail.
  def value(*)
    @value
  end
  
  # @return [String] pretty representation.
  def inspect
    "*#{@value.inspect}"
  end
  
  # @return [Array] embedded variables.
  def variables
    @value.variables
  end
  
  # @param other [Object, #value]
  # @return [Boolean] whether the value of the Tail is equal to the value of another Object.
  def ==(other)
    @value == other.value
  end
  
end

Instance Method Details

#==(other) ⇒ Boolean

Returns whether the value of the Tail is equal to the value of another Object.

Parameters:

Returns:

  • (Boolean) —

    whether the value of the Tail is equal to the value of another Object.



51
52
53
# File 'lib/porolog/tail.rb', line 51

def ==(other)
  @value == other.value
end

#inspect ⇒ String

Returns pretty representation.

Returns:

  • (String) —

    pretty representation.



40
41
42
# File 'lib/porolog/tail.rb', line 40

def inspect
  "*#{@value.inspect}"
end

#type ⇒ Symbol

Returns the type of the Tail, which should be :tail.

Returns:

  • (Symbol) —

    the type of the Tail, which should be :tail.



27
28
29
# File 'lib/porolog/tail.rb', line 27

def type
  :tail
end

#variables ⇒ Array

Returns embedded variables.

Returns:

  • (Array) —

    embedded variables.



45
46
47
# File 'lib/porolog/tail.rb', line 45

def variables
  @value.variables
end