Represents a rational number literal.
1.0r ^^^^
The numerator of the rational number.
1.5r # numerator 3
The denominator of the rational number.
1.5r # denominator 2
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15074
def initialize(source, node_id, location, flags, numerator, denominator)
@source = source
@node_id = node_id
@location = location
@flags = flags
@numerator = numerator
@denominator = denominator
end
Initialize a new RationalNode
node.
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15157
def self.type
:rational_node
end
Return a symbol representation of this node type. See ‘Node::type`.
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15163
def ===(other)
other.is_a?(RationalNode) &&
(flags === other.flags) &&
(numerator === other.numerator) &&
(denominator === other.denominator)
end
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15084
def accept(visitor)
visitor.visit_rational_node(self)
end
def accept: (Visitor
visitor) -> void
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15117
def binary?
flags.anybits?(IntegerBaseFlags::BINARY)
end
def binary?: () -> bool
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15089
def child_nodes
[]
end
def child_nodes
: () -> Array[nil | Node]
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15099
def comment_targets
[] #: Array[Prism::node | Location]
end
def comment_targets
: () -> Array[Node | Location]
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15094
def compact_child_nodes
[]
end
def compact_child_nodes
: () -> Array
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15104
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
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15122
def decimal?
flags.anybits?(IntegerBaseFlags::DECIMAL)
end
def decimal?: () -> bool
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15112
def deconstruct_keys(keys)
{ node_id: node_id, location: location, numerator: numerator, denominator: denominator }
end
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15132
def hexadecimal?
flags.anybits?(IntegerBaseFlags::HEXADECIMAL)
end
def hexadecimal?: () -> bool
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15147
def inspect
InspectVisitor.compose(self)
end
def inspect -> String
# File tmp/rubies/ruby-3.4.1/lib/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
Returns the value of the node as an IntegerNode
or a FloatNode
. This method is deprecated in favor of value
or numerator
/#denominator.
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15127
def octal?
flags.anybits?(IntegerBaseFlags::OCTAL)
end
def octal?: () -> bool
# File tmp/rubies/ruby-3.4.1/lib/prism/node.rb, line 15152
def type
:rational_node
end
Return a symbol representation of this node type. See ‘Node#type`.
# File tmp/rubies/ruby-3.4.1/lib/prism/node_ext.rb, line 114
def value
Rational(numerator, denominator)
end
Returns the value of the node as a Ruby Rational
.