Class: Prism::RationalNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::RationalNode
- Defined in:
- lib/prism/node.rb,
lib/prism/node_ext.rb,
ext/prism/api_node.c
Overview
Represents a rational number literal.
1.0r
^^^^
Instance Attribute Summary collapse
-
#denominator ⇒ Object
readonly
The denominator of the rational number.
-
#numerator ⇒ Object
readonly
The numerator of the rational number.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#binary? ⇒ Boolean
def binary?: () -> bool.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, numerator: self.numerator, denominator: self.denominator) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?numerator: Integer, ?denominator: Integer) -> RationalNode.
-
#decimal? ⇒ Boolean
def decimal?: () -> bool.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, numerator: Integer, denominator: Integer }.
-
#each_child_node ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator.
-
#hexadecimal? ⇒ Boolean
def hexadecimal?: () -> bool.
-
#initialize(source, node_id, location, flags, numerator, denominator) ⇒ RationalNode
constructor
Initialize a new RationalNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#numeric ⇒ Object
Returns the value of the node as an IntegerNode or a FloatNode.
-
#octal? ⇒ Boolean
def octal?: () -> bool.
-
#type ⇒ Object
Return a symbol representation of this node type.
-
#value ⇒ Object
Returns the value of the node as a Ruby Rational.
Constructor Details
#initialize(source, node_id, location, flags, numerator, denominator) ⇒ RationalNode
Initialize a new RationalNode node.
16200 16201 16202 16203 16204 16205 16206 16207 |
# File 'lib/prism/node.rb', line 16200 def initialize(source, node_id, location, flags, numerator, denominator) @source = source @node_id = node_id @location = location @flags = flags @numerator = numerator @denominator = denominator end |
Instance Attribute Details
#denominator ⇒ Object (readonly)
The denominator of the rational number.
1.5r # denominator 2
16276 16277 16278 |
# File 'lib/prism/node.rb', line 16276 def denominator @denominator end |
#numerator ⇒ Object (readonly)
The numerator of the rational number.
1.5r # numerator 3
16271 16272 16273 |
# File 'lib/prism/node.rb', line 16271 def numerator @numerator end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See Node::type.
16289 16290 16291 |
# File 'lib/prism/node.rb', line 16289 def self.type :rational_node end |
Instance Method Details
#===(other) ⇒ Object
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
16295 16296 16297 16298 16299 16300 |
# File 'lib/prism/node.rb', line 16295 def ===(other) other.is_a?(RationalNode) && (flags === other.flags) && (numerator === other.numerator) && (denominator === other.denominator) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
16210 16211 16212 |
# File 'lib/prism/node.rb', line 16210 def accept(visitor) visitor.visit_rational_node(self) end |
#binary? ⇒ Boolean
def binary?: () -> bool
16249 16250 16251 |
# File 'lib/prism/node.rb', line 16249 def binary? flags.anybits?(IntegerBaseFlags::BINARY) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
16215 16216 16217 |
# File 'lib/prism/node.rb', line 16215 def child_nodes [] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
16231 16232 16233 |
# File 'lib/prism/node.rb', line 16231 def comment_targets [] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
16226 16227 16228 |
# File 'lib/prism/node.rb', line 16226 def compact_child_nodes [] end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, numerator: self.numerator, denominator: self.denominator) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?numerator: Integer, ?denominator: Integer) -> RationalNode
16236 16237 16238 |
# File 'lib/prism/node.rb', line 16236 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? ⇒ Boolean
def decimal?: () -> bool
16254 16255 16256 |
# File 'lib/prism/node.rb', line 16254 def decimal? flags.anybits?(IntegerBaseFlags::DECIMAL) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, numerator: Integer, denominator: Integer }
16244 16245 16246 |
# File 'lib/prism/node.rb', line 16244 def deconstruct_keys(keys) { node_id: node_id, location: location, numerator: numerator, denominator: denominator } end |
#each_child_node ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator
16220 16221 16222 16223 |
# File 'lib/prism/node.rb', line 16220 def each_child_node return to_enum(:each_child_node) unless block_given? end |
#hexadecimal? ⇒ Boolean
def hexadecimal?: () -> bool
16264 16265 16266 |
# File 'lib/prism/node.rb', line 16264 def hexadecimal? flags.anybits?(IntegerBaseFlags::HEXADECIMAL) end |
#inspect ⇒ Object
def inspect -> String
16279 16280 16281 |
# File 'lib/prism/node.rb', line 16279 def inspect InspectVisitor.compose(self) end |
#numeric ⇒ Object
Returns the value of the node as an IntegerNode or a FloatNode. This method is deprecated in favor of #value or #numerator/#denominator.
123 124 125 126 127 128 129 130 131 |
# 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 |
#octal? ⇒ Boolean
def octal?: () -> bool
16259 16260 16261 |
# File 'lib/prism/node.rb', line 16259 def octal? flags.anybits?(IntegerBaseFlags::OCTAL) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
16284 16285 16286 |
# File 'lib/prism/node.rb', line 16284 def type :rational_node end |
#value ⇒ Object
Returns the value of the node as a Ruby Rational.
117 118 119 |
# File 'lib/prism/node_ext.rb', line 117 def value Rational(numerator, denominator) end |