Class: Prism::SelfNode

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

Overview

Represents the self keyword.

self
^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags) ⇒ SelfNode

Initialize a new SelfNode node.

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

Parameters:

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


29747
29748
29749
29750
29751
29752
# File 'lib/prism/node.rb', line 29747

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

Class Method Details

.type ⇒ :self_node

See Node.type.

: () -> :self_node

Returns:

  • (:self_node)


29829
29830
29831
# File 'lib/prism/node.rb', line 29829

def self.type
  :self_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


29845
29846
29847
# File 'lib/prism/node.rb', line 29845

def ===(other) # :nodoc:
  other.is_a?(SelfNode)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


29768
29769
29770
# File 'lib/prism/node.rb', line 29768

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

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

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


29775
29776
29777
# File 'lib/prism/node.rb', line 29775

def child_nodes
  []
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


29791
29792
29793
# File 'lib/prism/node.rb', line 29791

def compact_child_nodes
  []
end

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

:call-seq:

copy(**fields) -> SelfNode

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

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

Parameters:

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

Returns:



29801
29802
29803
# File 'lib/prism/node.rb', line 29801

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

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

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

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


29808
29809
29810
29811
29812
29813
29814
29815
29816
29817
# File 'lib/prism/node.rb', line 29808

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location]).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
    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)


29783
29784
29785
29786
# File 'lib/prism/node.rb', line 29783

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

end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


29834
29835
29836
# File 'lib/prism/node.rb', line 29834

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

#type ⇒ :self_node

See Node#type.

: () -> :self_node

Returns:

  • (:self_node)


29822
29823
29824
# File 'lib/prism/node.rb', line 29822

def type
  :self_node
end