Class: EagerBeaver::MethodMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/eager_beaver/method_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ MethodMatcher

Returns a new instance of MethodMatcher.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
# File 'lib/eager_beaver/method_matcher.rb', line 11

def initialize(block)
  block.call(self)

  raise ArgumentError, "matcher Proc must be given" \
    if matcher.nil?
  raise ArgumentError, "exactly one of new_method or new_method_code_maker Proc must be given" \
    if (new_method && new_method_code_maker) || (new_method.nil? && new_method_code_maker.nil?)

  self
end

Instance Attribute Details

#matcherObject

Returns the value of attribute matcher.



6
7
8
# File 'lib/eager_beaver/method_matcher.rb', line 6

def matcher
  @matcher
end

#missing_method_nameObject

Returns the value of attribute missing_method_name.



9
10
11
# File 'lib/eager_beaver/method_matcher.rb', line 9

def missing_method_name
  @missing_method_name
end

#new_methodObject

Returns the value of attribute new_method.



7
8
9
# File 'lib/eager_beaver/method_matcher.rb', line 7

def new_method
  @new_method
end

#new_method_code_makerObject

Returns the value of attribute new_method_code_maker.



8
9
10
# File 'lib/eager_beaver/method_matcher.rb', line 8

def new_method_code_maker
  @new_method_code_maker
end

#original_callerObject

Returns the value of attribute original_caller.



5
6
7
# File 'lib/eager_beaver/method_matcher.rb', line 5

def original_caller
  @original_caller
end

Instance Method Details

#match?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/eager_beaver/method_matcher.rb', line 22

def match?(method_name)
  self.missing_method_name = method_name.to_s
  self.instance_eval &matcher
end