Class: StringNode

Inherits:
Node
  • Object
show all
Defined in:
lib/nodes/basenodes.rb

Overview

See ArrayNode for a more complete Data Structure

Instance Attribute Summary

Attributes inherited from Node

#value

Instance Method Summary collapse

Methods inherited from Node

#to_s

Constructor Details

#initialize(value) ⇒ StringNode

Returns a new instance of StringNode.



50
51
52
53
54
55
56
# File 'lib/nodes/basenodes.rb', line 50

def initialize(value)
  if value.is_a?(String)
    super
  else
    super(value.join(' '))
  end
end

Instance Method Details

#*(other) ⇒ Object

Raises:

  • (NotImplementedError)


66
67
68
# File 'lib/nodes/basenodes.rb', line 66

def *(other)
  raise NotImplementedError, 'Multiplication is not implemented for Strings.'
end

#+(other) ⇒ Object

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/nodes/basenodes.rb', line 58

def +(other)
  raise NotImplementedError, 'Addition is not implemented for Strings.'
end

#-(other) ⇒ Object

Raises:

  • (NotImplementedError)


62
63
64
# File 'lib/nodes/basenodes.rb', line 62

def -(other)
  raise NotImplementedError, 'Subtraction is not implemented for Strings.'
end

#/(other) ⇒ Object

Raises:

  • (NotImplementedError)


70
71
72
# File 'lib/nodes/basenodes.rb', line 70

def /(other)
  raise NotImplementedError, 'Division is not implemented for Strings.'
end

#contains?(other) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/nodes/basenodes.rb', line 82

def contains?(other)
  return if @value.include?(other)
end

#evaluateObject



86
87
88
# File 'lib/nodes/basenodes.rb', line 86

def evaluate
  self
end

#to_fObject



78
79
80
# File 'lib/nodes/basenodes.rb', line 78

def to_f
  @value.to_f
end

#to_iObject



74
75
76
# File 'lib/nodes/basenodes.rb', line 74

def to_i
  @value.to_i
end