Class: Prism::RationalNode
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
PrismNode
|
|
|
Instance Chain:
self,
PrismNode
|
|
| Inherits: |
PrismNode
|
| Defined in: | lib/prism/node.rb, ext/prism/api_node.c, lib/prism/node_ext.rb |
Overview
Represents a rational number literal.
1.0r
^^^^
Class Method Summary
-
.new(source, node_id, location, flags, numerator, denominator) ⇒ RationalNode
constructor
Initialize a new
RationalNodenode. -
.type
Return a symbol representation of this node type.
Instance Attribute Summary
-
#binary? ⇒ Boolean
readonly
def binary?: () -> bool.
-
#decimal? ⇒ Boolean
readonly
def decimal?: () -> bool.
-
#denominator
readonly
The denominator of the rational number.
-
#hexadecimal? ⇒ Boolean
readonly
def hexadecimal?: () -> bool.
-
#numerator
readonly
The numerator of the rational number.
-
#octal? ⇒ Boolean
readonly
def octal?: () -> bool.
Instance Method Summary
-
#===(other)
Implements case-equality for the node.
-
#accept(visitor)
def accept: (Visitor visitor) -> void.
-
#child_nodes
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes
def compact_child_nodes: () -> Array.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, numerator: self.numerator, denominator: self.denominator)
def copy: (?node_id: Integer, ?location:
Location, ?flags: Integer, ?numerator: Integer, ?denominator: Integer) ->RationalNode. -
#deconstruct
Alias for #child_nodes.
- #deconstruct_keys(keys)
-
#inspect
def inspect -> String.
-
#numeric
Returns the value of the node as an
IntegerNodeor aFloatNode. -
#type
Return a symbol representation of this node type.
-
#value
Returns the value of the node as a Ruby Rational.
Constructor Details
.new(source, node_id, location, flags, numerator, denominator) ⇒ RationalNode
Initialize a new RationalNode node.
# File 'lib/prism/node.rb', line 13336
def initialize(source, node_id, location, flags, numerator, denominator) @source = source @node_id = node_id @location = location @flags = flags @numerator = numerator @denominator = denominator end
Class Method Details
.type
Return a symbol representation of this node type. See Node::type.
# File 'lib/prism/node.rb', line 13417
def self.type :rational_node end
Instance Attribute Details
#binary? ⇒ Boolean (readonly)
def binary?: () -> bool
# File 'lib/prism/node.rb', line 13379
def binary? flags.anybits?(IntegerBaseFlags::BINARY) end
#decimal? ⇒ Boolean (readonly)
def decimal?: () -> bool
# File 'lib/prism/node.rb', line 13384
def decimal? flags.anybits?(IntegerBaseFlags::DECIMAL) end
#denominator (readonly)
The denominator of the rational number.
1.5r # denominator 2
# File 'lib/prism/node.rb', line 13405
attr_reader :denominator
#hexadecimal? ⇒ Boolean (readonly)
def hexadecimal?: () -> bool
# File 'lib/prism/node.rb', line 13394
def hexadecimal? flags.anybits?(IntegerBaseFlags::HEXADECIMAL) end
#numerator (readonly)
The numerator of the rational number.
1.5r # numerator 3
# File 'lib/prism/node.rb', line 13401
attr_reader :numerator
#octal? ⇒ Boolean (readonly)
def octal?: () -> bool
# File 'lib/prism/node.rb', line 13389
def octal? flags.anybits?(IntegerBaseFlags::OCTAL) end
Instance Method Details
#===(other)
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
# File 'lib/prism/node.rb', line 13423
def ===(other) other.is_a?(RationalNode) && (flags === other.flags) && (numerator === other.numerator) && (denominator === other.denominator) end
#accept(visitor)
def accept: (Visitor visitor) -> void
# File 'lib/prism/node.rb', line 13346
def accept(visitor) visitor.visit_rational_node(self) end
#child_nodes Also known as: #deconstruct
def child_nodes: () -> Array[nil | Node]
# File 'lib/prism/node.rb', line 13351
def child_nodes [] end
#comment_targets
def comment_targets: () -> Array[Node | Location]
# File 'lib/prism/node.rb', line 13361
def comment_targets [] #: Array[Prism::node | Location] end
#compact_child_nodes
def compact_child_nodes: () -> Array
# File 'lib/prism/node.rb', line 13356
def compact_child_nodes [] end
#copy(node_id: self.node_id, location: self.location, flags: self.flags, numerator: self.numerator, denominator: self.denominator)
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?numerator: Integer, ?denominator: Integer) -> RationalNode
# File 'lib/prism/node.rb', line 13366
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
#deconstruct
Alias for #child_nodes.
# File 'lib/prism/node.rb', line 13371
alias deconstruct child_nodes
#deconstruct_keys(keys)
# File 'lib/prism/node.rb', line 13374
def deconstruct_keys(keys) { node_id: node_id, location: location, numerator: numerator, denominator: denominator } end
#inspect
def inspect -> String
# File 'lib/prism/node.rb', line 13407
def inspect InspectVisitor.compose(self) end
#numeric
Returns the value of the node as an IntegerNode or a FloatNode. This
method is deprecated in favor of #value or #numerator/#denominator.
# 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
#type
Return a symbol representation of this node type. See Node#type.
# File 'lib/prism/node.rb', line 13412
def type :rational_node end
#value
Returns the value of the node as a Ruby Rational.
# File 'lib/prism/node_ext.rb', line 117
def value Rational(numerator, denominator) end