class Prism::RationalNode - Documentation for Ruby 4.0
Description: class Prism::RationalNode: Represents a rational number literal.
Keywords: ruby,class,Prism::RationalNode

🔍

No recent searches

# 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)
Source

    # File lib/prism/node.rb, line 16192
    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.

type ()
Source

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

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

### Public Instance Methods

=== (other)
Source

    # File lib/prism/node.rb, line 16287
    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.

accept (visitor)
Source

    # File lib/prism/node.rb, line 16202
    def accept(visitor)
      visitor.visit_rational_node(self)
    end

def accept: (`Visitor` visitor) -> void

binary? ()
Source

    # File lib/prism/node.rb, line 16241
    def binary?
      flags.anybits?(IntegerBaseFlags::BINARY)
    end

def binary?: () -> bool

child_nodes ()
Source

    # File lib/prism/node.rb, line 16207
    def child_nodes
      []
    end

def `child_nodes`: () -> Array

Also aliased as: deconstruct
comment_targets ()
Source

    # File lib/prism/node.rb, line 16223
    def comment_targets
      [] #: Array[Prism::node | Location]
    end

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

compact_child_nodes ()
Source

    # File lib/prism/node.rb, line 16218
    def compact_child_nodes
      []
    end

def `compact_child_nodes`: () -> Array

copy (node_id: self.node_id, location: self.location, flags: self.flags, numerator: self.numerator, denominator: self.denominator)
Source

    # File lib/prism/node.rb, line 16228
    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

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

decimal? ()
Source

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

def decimal?: () -> bool

deconstruct ()

def deconstruct: () -> Array

Alias for: child_nodes
deconstruct_keys (keys)
Source

    # File lib/prism/node.rb, line 16236
    def deconstruct_keys(keys)
      { node_id: node_id, location: location, numerator: numerator, denominator: denominator }
    end

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

each_child_node ()
Source

    # File lib/prism/node.rb, line 16212
    def each_child_node
      return to_enum(:each_child_node) unless block_given?

    end

def `each_child_node`: () { (Prism::node) -> void } -> void | () -> Enumerator

hexadecimal? ()
Source

    # File lib/prism/node.rb, line 16256
    def hexadecimal?
      flags.anybits?(IntegerBaseFlags::HEXADECIMAL)
    end

def hexadecimal?: () -> bool

inspect ()
Source

    # File lib/prism/node.rb, line 16271
    def inspect
      InspectVisitor.compose(self)
    end

def inspect -> `String`

numeric ()
Source

    # File lib/prism/node_ext.rb, line 123
    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.

octal? ()
Source

    # File lib/prism/node.rb, line 16251
    def octal?
      flags.anybits?(IntegerBaseFlags::OCTAL)
    end

def octal?: () -> bool

type ()
Source

    # File lib/prism/node.rb, line 16276
    def type
      :rational_node
    end

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

value ()
Source

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

Returns the value of the node as a Ruby `Rational`.