Class: Mutant::Matcher::Method::Classifier

Inherits:
Object
  • Object
show all
Includes:
Adamantium::Flat
Defined in:
lib/mutant/matcher/method/classifier.rb

Overview

A classifier for input strings

Constant Summary collapse

TABLE =
{
  '.' => Matcher::ScopeMethods::Singleton,
  '#' => Matcher::ScopeMethods::Instance
}.freeze
SCOPE_FORMAT =
/\A([^#.]+)(\.|#)(.+)\z/.freeze
SCOPE_NAME_POSITION =

Positions of captured regexp groups Freezing fixnums to avoid their singleton classes are patched.

1.freeze
SCOPE_SYMBOL_POSITION =
2.freeze
METHOD_NAME_POSITION =
3.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#matchMatche (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return match

Returns:

  • (Matche)


71
72
73
# File 'lib/mutant/matcher/method/classifier.rb', line 71

def match
  @match
end

Class Method Details

.run(input) ⇒ Matcher::Method?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run classifier

Parameters:

  • input (String)

Returns:

  • (Matcher::Method)

    returns matcher when input is in

  • (nil)

    returns nil otherwise



35
36
37
38
39
# File 'lib/mutant/matcher/method/classifier.rb', line 35

def self.run(input)
  match = SCOPE_FORMAT.match(input)
  return unless match
  new(match).matcher
end

Instance Method Details

#matcherMatcher::Method

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return method matcher

Returns:



47
48
49
# File 'lib/mutant/matcher/method/classifier.rb', line 47

def matcher
  scope_matcher.matcher.new(scope, method)
end

#methodMethod, UnboundMethod

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return method

Returns:



58
59
60
61
62
# File 'lib/mutant/matcher/method/classifier.rb', line 58

def method
  scope_matcher.methods.detect do |method|
    method.name == method_name
  end || raise("Cannot find #{method_name} for #{scope}")
end