Class: Unparser::Preprocessor::Infinity

Inherits:
Unparser::Preprocessor show all
Defined in:
lib/unparser/preprocessor.rb

Overview

Preprocessor transforming numeric nodes with infinity as value to round trippable equivalent.

Constant Summary collapse

NEG_INFINITY =
- 1)

Constants inherited from Unparser::Preprocessor

EMPTY, REGISTRY

Instance Method Summary collapse

Methods inherited from Unparser::Preprocessor

run

Methods included from NodeHelpers

#n, #s

Instance Method Details

#resultParser::AST::Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return preprocessor result

Returns:

  • (Parser::AST::Node)


121
122
123
124
125
126
127
128
129
130
131
# File 'lib/unparser/preprocessor.rb', line 121

def result
  value = node.children.first
  case value
  when Float::INFINITY
    s(:const, s(:const, nil, :Float), :INFINITY)
  when NEG_INFINITY
    s(:send, s(:const, s(:const, nil, :Float), :INFINITY), :-@)
  else
    node
  end
end