Class: RubyNext::Language::Rewriters::FindPattern

Inherits:
PatternMatching show all
Defined in:
lib/ruby-next/language/rewriters/3.0/find_pattern.rb

Overview

Separate pattern matching rewriter for Ruby 2.7 to transpile only case…in with a find pattern

Constant Summary collapse

NAME =
"pattern-matching-find-pattern"
SYNTAX_PROBE =
"case 0; in [*,0,*]; true; else; 1; end"
MIN_SUPPORTED_VERSION =
Gem::Version.new("3.0.0")

Constants inherited from PatternMatching

PatternMatching::ALTERNATION_MARKER, PatternMatching::CURRENT_HASH_KEY, PatternMatching::MATCHEE, PatternMatching::MATCHEE_ARR, PatternMatching::MATCHEE_HASH

Instance Attribute Summary

Attributes inherited from Base

#locals

Instance Method Summary collapse

Methods inherited from PatternMatching

#on_match_pattern_p

Methods inherited from Base

ast?, #initialize, #s

Methods inherited from Abstract

ast?, #initialize, text?, unsupported_syntax?, unsupported_version?

Constructor Details

This class inherits a constructor from RubyNext::Language::Rewriters::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RubyNext::Language::Rewriters::PatternMatching

Instance Method Details

#on_case_match(node) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/ruby-next/language/rewriters/3.0/find_pattern.rb', line 15

def on_case_match(node)
  @has_find_pattern = false
  process_regular_node(node).then do |new_node|
    return new_node unless has_find_pattern
    super(node)
  end
end

#on_find_pattern(node) ⇒ Object



31
32
33
34
# File 'lib/ruby-next/language/rewriters/3.0/find_pattern.rb', line 31

def on_find_pattern(node)
  @has_find_pattern = true
  super(node)
end

#on_match_pattern(node) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/ruby-next/language/rewriters/3.0/find_pattern.rb', line 23

def on_match_pattern(node)
  @has_find_pattern = false
  process_regular_node(node).then do |new_node|
    return new_node unless has_find_pattern
    super(node)
  end
end