class Prism::RationalNode

Represents a rational number literal.

1.0r
^^^^

Attributes

denominator[R]

The denominator of the rational number.

1.5r # denominator 2
numerator[R]

The numerator of the rational number.

1.5r # numerator 3

Public Class Methods

new(source, node_id, location, flags, numerator, denominator) click to toggle source

Initialize a new RationalNode node.

# File prism/node.rb, line 13617
def initialize(source, node_id, location, flags, numerator, denominator)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @numerator = numerator
  @denominator = denominator
end
type() click to toggle source

Return a symbol representation of this node type. See ‘Node::type`.

# File prism/node.rb, line 13700
def self.type
  :rational_node
end

Public Instance Methods

===(other) click to toggle source

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.

# File prism/node.rb, line 13706
def ===(other)
  other.is_a?(RationalNode) &&
    (flags === other.flags) &&
    (numerator === other.numerator) &&
    (denominator === other.denominator)
end
accept(visitor) click to toggle source

def accept: (Visitor visitor) -> void

# File prism/node.rb, line 13627
def accept(visitor)
  visitor.visit_rational_node(self)
end
binary?() click to toggle source

def binary?: () -> bool

# File prism/node.rb, line 13660
def binary?
  flags.anybits?(IntegerBaseFlags::BINARY)
end
child_nodes() click to toggle source

def child_nodes: () -> Array[nil | Node]

# File prism/node.rb, line 13632
def child_nodes
  []
end
Also aliased as: deconstruct
comment_targets() click to toggle source

def comment_targets: () -> Array[Node | Location]

# File prism/node.rb, line 13642
def comment_targets
  [] #: Array[Prism::node | Location]
end
compact_child_nodes() click to toggle source

def compact_child_nodes: () -> Array

# File prism/node.rb, line 13637
def compact_child_nodes
  []
end
copy(node_id: self.node_id, location: self.location, flags: self.flags, numerator: self.numerator, denominator: self.denominator) click to toggle source

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?numerator: Integer, ?denominator: Integer) -> RationalNode

# File prism/node.rb, line 13647
def copy(node_id: self.node_id, location: self.location, flags: self.flags, numerator: self.numerator, denominator: self.denominator)
  RationalNode.new(source, node_id, location, flags, numerator, denominator)
end
decimal?() click to toggle source

def decimal?: () -> bool

# File prism/node.rb, line 13665
def decimal?
  flags.anybits?(IntegerBaseFlags::DECIMAL)
end
deconstruct()

def deconstruct: () -> Array[nil | Node]

Alias for: child_nodes
deconstruct_keys(keys) click to toggle source

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, numerator: Integer, denominator: Integer }

# File prism/node.rb, line 13655
def deconstruct_keys(keys)
  { node_id: node_id, location: location, numerator: numerator, denominator: denominator }
end
hexadecimal?() click to toggle source

def hexadecimal?: () -> bool

# File prism/node.rb, line 13675
def hexadecimal?
  flags.anybits?(IntegerBaseFlags::HEXADECIMAL)
end
inspect() click to toggle source

def inspect -> String

# File prism/node.rb, line 13690
def inspect
  InspectVisitor.compose(self)
end
numeric() click to toggle source

Returns the value of the node as an IntegerNode or a FloatNode. This method is deprecated in favor of value or numerator/#denominator.

# File prism/node_ext.rb, line 120
def numeric
  deprecated("value", "numerator", "denominator")

  if denominator == 1
    IntegerNode.new(source, -1, location.chop, flags, numerator)
  else
    FloatNode.new(source, -1, location.chop, 0, numerator.to_f / denominator)
  end
end
octal?() click to toggle source

def octal?: () -> bool

# File prism/node.rb, line 13670
def octal?
  flags.anybits?(IntegerBaseFlags::OCTAL)
end
type() click to toggle source

Return a symbol representation of this node type. See ‘Node#type`.

# File prism/node.rb, line 13695
def type
  :rational_node
end
value() click to toggle source

Returns the value of the node as a Ruby Rational.

# File prism/node_ext.rb, line 114
def value
  Rational(numerator, denominator)
end