Class: Prism::IntegerNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c

Overview

Represents an integer number literal.

1
^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, value) ⇒ IntegerNode

Initialize a new IntegerNode node.

: (Source source, Integer node_id, Location location, Integer flags, Integer value) -> void

Parameters:

  • source (Source)
  • node_id (Integer)
  • location (Location)
  • flags (Integer)
  • value (Integer)


19124
19125
19126
19127
19128
19129
19130
# File 'lib/prism/node.rb', line 19124

def initialize(source, node_id, location, flags, value)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @value = value
end

Class Method Details

.type ⇒ :integer_node

See Node.type.

: () -> :integer_node

Returns:

  • (:integer_node)


19208
19209
19210
# File 'lib/prism/node.rb', line 19208

def self.type
  :integer_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


19266
19267
19268
19269
19270
# File 'lib/prism/node.rb', line 19266

def ===(other) # :nodoc:
  other.is_a?(IntegerNode) &&
    (flags === other.flags) &&
    (value === other.value)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


19146
19147
19148
# File 'lib/prism/node.rb', line 19146

def accept(visitor)
  visitor.visit_integer_node(self)
end

#binary? ⇒ Boolean

:category: Flags 0b prefix

: () -> bool

Returns:

  • (Boolean)


19223
19224
19225
# File 'lib/prism/node.rb', line 19223

def binary?
  flags.anybits?(IntegerBaseFlags::BINARY)
end

#child_nodes ⇒ Array[node?] Also known as: deconstruct

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


19153
19154
19155
# File 'lib/prism/node.rb', line 19153

def child_nodes
  []
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


19169
19170
19171
# File 'lib/prism/node.rb', line 19169

def compact_child_nodes
  []
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value) ⇒ IntegerNode

:call-seq:

copy(**fields) -> IntegerNode

Creates a copy of self with the given fields, using self as the template.

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Integer) -> IntegerNode

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • value: (Integer) (defaults to: self.value)

Returns:



19179
19180
19181
# File 'lib/prism/node.rb', line 19179

def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value)
  IntegerNode.new(source, node_id, location, flags, value)
end

#decimal? ⇒ Boolean

:category: Flags 0d or no prefix

: () -> bool

Returns:

  • (Boolean)


19231
19232
19233
# File 'lib/prism/node.rb', line 19231

def decimal?
  flags.anybits?(IntegerBaseFlags::DECIMAL)
end

#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]

: (Array? keys) -> Hash[Symbol, untyped]

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
# File 'lib/prism/node.rb', line 19186

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location value]).each_with_object(
    {} #: Hash[Symbol, untyped]
  ) do |key, deconstructed|
    case key
    when :node_id                 then deconstructed[:node_id] = self.node_id
    when :location                then deconstructed[:location] = self.location
    when :value                   then deconstructed[:value] = self.value
    end
  end
end

#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void

See Node.each_child_node.

: () -> Enumerator[node, void] : () { (node) -> void } -> void

Overloads:

  • #each_child_node ⇒ Enumerator[node, void]

    Returns:

    • (Enumerator[node, void])
  • #each_child_node ⇒ void

    This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (node)

Yield Returns:

  • (void)


19161
19162
19163
19164
# File 'lib/prism/node.rb', line 19161

def each_child_node(&blk)
  return to_enum(:each_child_node) unless block_given?

end

#hexadecimal? ⇒ Boolean

:category: Flags 0x prefix

: () -> bool

Returns:

  • (Boolean)


19247
19248
19249
# File 'lib/prism/node.rb', line 19247

def hexadecimal?
  flags.anybits?(IntegerBaseFlags::HEXADECIMAL)
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


19213
19214
19215
# File 'lib/prism/node.rb', line 19213

def inspect # :nodoc:
  InspectVisitor.compose(self)
end

#octal? ⇒ Boolean

:category: Flags 0o or 0 prefix

: () -> bool

Returns:

  • (Boolean)


19239
19240
19241
# File 'lib/prism/node.rb', line 19239

def octal?
  flags.anybits?(IntegerBaseFlags::OCTAL)
end

#type ⇒ :integer_node

See Node#type.

: () -> :integer_node

Returns:

  • (:integer_node)


19201
19202
19203
# File 'lib/prism/node.rb', line 19201

def type
  :integer_node
end

#value ⇒ Integer

:call-seq:

value -> Integer

The value of the integer literal as a number.

: () -> Integer

Returns:

  • (Integer)


19257
19258
19259
# File 'lib/prism/node.rb', line 19257

def value
  @value
end