Class: Prism::InterpolatedMatchLastLineNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::InterpolatedMatchLastLineNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a regular expression literal that contains interpolation that is being used in the predicate of a conditional to implicitly match against the last line read by an IO object.
if /foo #{bar} baz/ then end
^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#closing_loc ⇒ Object
readonly
attr_reader closing_loc: Location.
-
#opening_loc ⇒ Object
readonly
attr_reader opening_loc: Location.
-
#parts ⇒ Object
readonly
attr_reader parts: Array.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#ascii_8bit? ⇒ Boolean
def ascii_8bit?: () -> bool.
-
#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) -> InterpolatedMatchLastLineNode.
- #deconstruct_keys(keys) ⇒ Object
-
#euc_jp? ⇒ Boolean
def euc_jp?: () -> bool.
-
#extended? ⇒ Boolean
def extended?: () -> bool.
-
#ignore_case? ⇒ Boolean
def ignore_case?: () -> bool.
-
#initialize(opening_loc, parts, closing_loc, flags, location) ⇒ InterpolatedMatchLastLineNode
constructor
def initialize: (opening_loc: Location, parts: Array, closing_loc: Location, flags: Integer, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#multi_line? ⇒ Boolean
def multi_line?: () -> bool.
-
#once? ⇒ Boolean
def once?: () -> bool.
-
#opening ⇒ Object
def opening: () -> String.
- #set_newline_flag(newline_marked) ⇒ Object
-
#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.
-
#utf_8? ⇒ Boolean
def utf_8?: () -> bool.
-
#windows_31j? ⇒ Boolean
def windows_31j?: () -> bool.
Constructor Details
#initialize(opening_loc, parts, closing_loc, flags, location) ⇒ InterpolatedMatchLastLineNode
def initialize: (opening_loc: Location, parts: Array, closing_loc: Location, flags: Integer, location: Location) -> void
7812 7813 7814 7815 7816 7817 7818 |
# File 'lib/prism/node.rb', line 7812 def initialize(opening_loc, parts, closing_loc, flags, location) @opening_loc = opening_loc @parts = parts @closing_loc = closing_loc @flags = flags @location = location end |
Instance Attribute Details
#closing_loc ⇒ Object (readonly)
attr_reader closing_loc: Location
7806 7807 7808 |
# File 'lib/prism/node.rb', line 7806 def closing_loc @closing_loc end |
#opening_loc ⇒ Object (readonly)
attr_reader opening_loc: Location
7800 7801 7802 |
# File 'lib/prism/node.rb', line 7800 def opening_loc @opening_loc end |
#parts ⇒ Object (readonly)
attr_reader parts: Array
7803 7804 7805 |
# File 'lib/prism/node.rb', line 7803 def parts @parts end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
7821 7822 7823 |
# File 'lib/prism/node.rb', line 7821 def accept(visitor) visitor.visit_interpolated_match_last_line_node(self) end |
#ascii_8bit? ⇒ Boolean
def ascii_8bit?: () -> bool
7895 7896 7897 |
# File 'lib/prism/node.rb', line 7895 def ascii_8bit? flags.anybits?(RegularExpressionFlags::ASCII_8BIT) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
7831 7832 7833 |
# File 'lib/prism/node.rb', line 7831 def child_nodes [*parts] end |
#closing ⇒ Object
def closing: () -> String
7870 7871 7872 |
# File 'lib/prism/node.rb', line 7870 def closing closing_loc.slice end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
7841 7842 7843 |
# File 'lib/prism/node.rb', line 7841 def comment_targets [opening_loc, *parts, closing_loc] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
7836 7837 7838 |
# File 'lib/prism/node.rb', line 7836 def compact_child_nodes [*parts] end |
#copy(**params) ⇒ Object
def copy: (**params) -> InterpolatedMatchLastLineNode
7846 7847 7848 7849 7850 7851 7852 7853 7854 |
# File 'lib/prism/node.rb', line 7846 def copy(**params) InterpolatedMatchLastLineNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:parts) { parts }, params.fetch(:closing_loc) { closing_loc }, params.fetch(:flags) { flags }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
7860 7861 7862 |
# File 'lib/prism/node.rb', line 7860 def deconstruct_keys(keys) { opening_loc: opening_loc, parts: parts, closing_loc: closing_loc, flags: flags, location: location } end |
#euc_jp? ⇒ Boolean
def euc_jp?: () -> bool
7890 7891 7892 |
# File 'lib/prism/node.rb', line 7890 def euc_jp? flags.anybits?(RegularExpressionFlags::EUC_JP) end |
#extended? ⇒ Boolean
def extended?: () -> bool
7880 7881 7882 |
# File 'lib/prism/node.rb', line 7880 def extended? flags.anybits?(RegularExpressionFlags::EXTENDED) end |
#ignore_case? ⇒ Boolean
def ignore_case?: () -> bool
7875 7876 7877 |
# File 'lib/prism/node.rb', line 7875 def ignore_case? flags.anybits?(RegularExpressionFlags::IGNORE_CASE) end |
#inspect(inspector = NodeInspector.new) ⇒ Object
7914 7915 7916 7917 7918 7919 7920 7921 7922 |
# File 'lib/prism/node.rb', line 7914 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" inspector << "├── parts: #{inspector.list("#{inspector.prefix}│ ", parts)}" inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n" flags = [("ignore_case" if ignore_case?), ("extended" if extended?), ("multi_line" if multi_line?), ("euc_jp" if euc_jp?), ("ascii_8bit" if ascii_8bit?), ("windows_31j" if windows_31j?), ("utf_8" if utf_8?), ("once" if once?)].compact inspector << "└── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n" inspector.to_str end |
#multi_line? ⇒ Boolean
def multi_line?: () -> bool
7885 7886 7887 |
# File 'lib/prism/node.rb', line 7885 def multi_line? flags.anybits?(RegularExpressionFlags::MULTI_LINE) end |
#once? ⇒ Boolean
def once?: () -> bool
7910 7911 7912 |
# File 'lib/prism/node.rb', line 7910 def once? flags.anybits?(RegularExpressionFlags::ONCE) end |
#opening ⇒ Object
def opening: () -> String
7865 7866 7867 |
# File 'lib/prism/node.rb', line 7865 def opening opening_loc.slice end |
#set_newline_flag(newline_marked) ⇒ Object
7825 7826 7827 7828 |
# File 'lib/prism/node.rb', line 7825 def set_newline_flag(newline_marked) first = parts.first first.set_newline_flag(newline_marked) if first 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
7938 7939 7940 |
# File 'lib/prism/node.rb', line 7938 def type :interpolated_match_last_line_node end |
#utf_8? ⇒ Boolean
def utf_8?: () -> bool
7905 7906 7907 |
# File 'lib/prism/node.rb', line 7905 def utf_8? flags.anybits?(RegularExpressionFlags::UTF_8) end |
#windows_31j? ⇒ Boolean
def windows_31j?: () -> bool
7900 7901 7902 |
# File 'lib/prism/node.rb', line 7900 def windows_31j? flags.anybits?(RegularExpressionFlags::WINDOWS_31J) end |