Class: Prism::CallAndWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::CallAndWriteNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents the use of the &&= operator on a call.
foo.bar &&= value
^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
attr_reader arguments: ArgumentsNode?.
-
#call_operator_loc ⇒ Object
readonly
attr_reader call_operator_loc: Location?.
-
#closing_loc ⇒ Object
readonly
attr_reader closing_loc: Location?.
-
#message_loc ⇒ Object
readonly
attr_reader message_loc: Location?.
-
#opening_loc ⇒ Object
readonly
attr_reader opening_loc: Location?.
-
#operator_loc ⇒ Object
readonly
attr_reader operator_loc: Location.
-
#read_name ⇒ Object
readonly
attr_reader read_name: String.
-
#receiver ⇒ Object
readonly
attr_reader receiver: Node?.
-
#value ⇒ Object
readonly
attr_reader value: Node.
-
#write_name ⇒ Object
readonly
attr_reader write_name: String.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#call_operator ⇒ Object
def call_operator: () -> String?.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#closing ⇒ Object
def closing: () -> String?.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(**params) ⇒ Object
def copy: (**params) -> CallAndWriteNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location].
-
#initialize(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator_loc, value, location) ⇒ CallAndWriteNode
constructor
def initialize: (receiver: Node?, call_operator_loc: Location?, message_loc: Location?, opening_loc: Location?, arguments: ArgumentsNode?, closing_loc: Location?, flags: Integer, read_name: String, write_name: String, operator_loc: Location, value: Node, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#message ⇒ Object
def message: () -> String?.
-
#opening ⇒ Object
def opening: () -> String?.
-
#operator ⇒ Object
def operator: () -> String.
-
#safe_navigation? ⇒ Boolean
def safe_navigation?: () -> bool.
-
#type ⇒ Object
Sometimes you want to check an instance of a node against a list of classes to see what kind of behavior to perform.
-
#variable_call? ⇒ Boolean
def variable_call?: () -> bool.
Constructor Details
#initialize(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator_loc, value, location) ⇒ CallAndWriteNode
def initialize: (receiver: Node?, call_operator_loc: Location?, message_loc: Location?, opening_loc: Location?, arguments: ArgumentsNode?, closing_loc: Location?, flags: Integer, read_name: String, write_name: String, operator_loc: Location, value: Node, location: Location) -> void
1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 |
# File 'lib/prism/node.rb', line 1771 def initialize(receiver, call_operator_loc, , opening_loc, arguments, closing_loc, flags, read_name, write_name, operator_loc, value, location) @receiver = receiver @call_operator_loc = call_operator_loc @message_loc = @opening_loc = opening_loc @arguments = arguments @closing_loc = closing_loc @flags = flags @read_name = read_name @write_name = write_name @operator_loc = operator_loc @value = value @location = location end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
attr_reader arguments: ArgumentsNode?
1750 1751 1752 |
# File 'lib/prism/node.rb', line 1750 def arguments @arguments end |
#call_operator_loc ⇒ Object (readonly)
attr_reader call_operator_loc: Location?
1741 1742 1743 |
# File 'lib/prism/node.rb', line 1741 def call_operator_loc @call_operator_loc end |
#closing_loc ⇒ Object (readonly)
attr_reader closing_loc: Location?
1753 1754 1755 |
# File 'lib/prism/node.rb', line 1753 def closing_loc @closing_loc end |
#message_loc ⇒ Object (readonly)
attr_reader message_loc: Location?
1744 1745 1746 |
# File 'lib/prism/node.rb', line 1744 def @message_loc end |
#opening_loc ⇒ Object (readonly)
attr_reader opening_loc: Location?
1747 1748 1749 |
# File 'lib/prism/node.rb', line 1747 def opening_loc @opening_loc end |
#operator_loc ⇒ Object (readonly)
attr_reader operator_loc: Location
1765 1766 1767 |
# File 'lib/prism/node.rb', line 1765 def operator_loc @operator_loc end |
#read_name ⇒ Object (readonly)
attr_reader read_name: String
1759 1760 1761 |
# File 'lib/prism/node.rb', line 1759 def read_name @read_name end |
#receiver ⇒ Object (readonly)
attr_reader receiver: Node?
1738 1739 1740 |
# File 'lib/prism/node.rb', line 1738 def receiver @receiver end |
#value ⇒ Object (readonly)
attr_reader value: Node
1768 1769 1770 |
# File 'lib/prism/node.rb', line 1768 def value @value end |
#write_name ⇒ Object (readonly)
attr_reader write_name: String
1762 1763 1764 |
# File 'lib/prism/node.rb', line 1762 def write_name @write_name end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
1787 1788 1789 |
# File 'lib/prism/node.rb', line 1787 def accept(visitor) visitor.visit_call_and_write_node(self) end |
#call_operator ⇒ Object
def call_operator: () -> String?
1837 1838 1839 |
# File 'lib/prism/node.rb', line 1837 def call_operator call_operator_loc&.slice end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
1792 1793 1794 |
# File 'lib/prism/node.rb', line 1792 def child_nodes [receiver, arguments, value] end |
#closing ⇒ Object
def closing: () -> String?
1852 1853 1854 |
# File 'lib/prism/node.rb', line 1852 def closing closing_loc&.slice end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
1806 1807 1808 |
# File 'lib/prism/node.rb', line 1806 def comment_targets [*receiver, *call_operator_loc, *, *opening_loc, *arguments, *closing_loc, operator_loc, value] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
1797 1798 1799 1800 1801 1802 1803 |
# File 'lib/prism/node.rb', line 1797 def compact_child_nodes compact = [] compact << receiver if receiver compact << arguments if arguments compact << value compact end |
#copy(**params) ⇒ Object
def copy: (**params) -> CallAndWriteNode
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 |
# File 'lib/prism/node.rb', line 1811 def copy(**params) CallAndWriteNode.new( params.fetch(:receiver) { receiver }, params.fetch(:call_operator_loc) { call_operator_loc }, params.fetch(:message_loc) { }, params.fetch(:opening_loc) { opening_loc }, params.fetch(:arguments) { arguments }, params.fetch(:closing_loc) { closing_loc }, params.fetch(:flags) { flags }, params.fetch(:read_name) { read_name }, params.fetch(:write_name) { write_name }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:value) { value }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location]
1832 1833 1834 |
# File 'lib/prism/node.rb', line 1832 def deconstruct_keys(keys) { receiver: receiver, call_operator_loc: call_operator_loc, message_loc: , opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, flags: flags, read_name: read_name, write_name: write_name, operator_loc: operator_loc, value: value, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 |
# File 'lib/prism/node.rb', line 1871 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) if (receiver = self.receiver).nil? inspector << "├── receiver: ∅\n" else inspector << "├── receiver:\n" inspector << receiver.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end inspector << "├── call_operator_loc: #{inspector.location(call_operator_loc)}\n" inspector << "├── message_loc: #{inspector.location()}\n" inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" if (arguments = self.arguments).nil? inspector << "├── arguments: ∅\n" else inspector << "├── arguments:\n" inspector << arguments.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" flags = [("safe_navigation" if ), ("variable_call" if variable_call?)].compact inspector << "├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n" inspector << "├── read_name: #{read_name.inspect}\n" inspector << "├── write_name: #{write_name.inspect}\n" inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" inspector << "└── value:\n" inspector << inspector.child_node(value, " ") inspector.to_str end |
#message ⇒ Object
def message: () -> String?
1842 1843 1844 |
# File 'lib/prism/node.rb', line 1842 def &.slice end |
#opening ⇒ Object
def opening: () -> String?
1847 1848 1849 |
# File 'lib/prism/node.rb', line 1847 def opening opening_loc&.slice end |
#operator ⇒ Object
def operator: () -> String
1867 1868 1869 |
# File 'lib/prism/node.rb', line 1867 def operator operator_loc.slice end |
#safe_navigation? ⇒ Boolean
def safe_navigation?: () -> bool
1857 1858 1859 |
# File 'lib/prism/node.rb', line 1857 def flags.anybits?(CallNodeFlags::SAFE_NAVIGATION) end |
#type ⇒ Object
Sometimes you want to check an instance of a node against a list of
classes to see what kind of behavior to perform. Usually this is done by
calling [cls1, cls2].include?(node.class) or putting the node into a
case statement and doing case node; when cls1; when cls2; end. Both of
these approaches are relatively slow because of the constant lookups,
method calls, and/or array allocations.
Instead, you can call #type, which will return to you a symbol that you can use for comparison. This is faster than the other approaches because it uses a single integer comparison, but also because if you're on CRuby you can take advantage of the fact that case statements with all symbol keys will use a jump table.
def type: () -> Symbol
1913 1914 1915 |
# File 'lib/prism/node.rb', line 1913 def type :call_and_write_node end |
#variable_call? ⇒ Boolean
def variable_call?: () -> bool
1862 1863 1864 |
# File 'lib/prism/node.rb', line 1862 def variable_call? flags.anybits?(CallNodeFlags::VARIABLE_CALL) end |