Class: SyntaxTree::FloatLiteral

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

FloatLiteral represents a floating point number literal.

1.0

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(value:, location:) ⇒ FloatLiteral

Returns a new instance of FloatLiteral.



5258
5259
5260
5261
5262
# File 'lib/syntax_tree/node.rb', line 5258

def initialize(value:, location:)
  @value = value
  @location = location
  @comments = []
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5256
5257
5258
# File 'lib/syntax_tree/node.rb', line 5256

def comments
  @comments
end

#valueObject (readonly)

String

the value of the floating point number literal



5253
5254
5255
# File 'lib/syntax_tree/node.rb', line 5253

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5293
5294
5295
# File 'lib/syntax_tree/node.rb', line 5293

def ===(other)
  other.is_a?(FloatLiteral) && value === other.value
end

#accept(visitor) ⇒ Object



5264
5265
5266
# File 'lib/syntax_tree/node.rb', line 5264

def accept(visitor)
  visitor.visit_float(self)
end

#child_nodesObject Also known as: deconstruct



5268
5269
5270
# File 'lib/syntax_tree/node.rb', line 5268

def child_nodes
  []
end

#copy(value: nil, location: nil) ⇒ Object



5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
# File 'lib/syntax_tree/node.rb', line 5272

def copy(value: nil, location: nil)
  node =
    FloatLiteral.new(
      value: value || self.value,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



5285
5286
5287
# File 'lib/syntax_tree/node.rb', line 5285

def deconstruct_keys(_keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



5289
5290
5291
# File 'lib/syntax_tree/node.rb', line 5289

def format(q)
  q.text(value)
end