Class: Aspect4r::Model::MethodMatcher
- Inherits:
-
Object
- Object
- Aspect4r::Model::MethodMatcher
- Defined in:
- lib/aspect4r/model/method_matcher.rb
Instance Method Summary collapse
-
#initialize(*match_data) ⇒ MethodMatcher
constructor
A new instance of MethodMatcher.
- #match?(method) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(*match_data) ⇒ MethodMatcher
Returns a new instance of MethodMatcher.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/aspect4r/model/method_matcher.rb', line 4 def initialize *match_data @match_data = match_data # Performance improvement ideas: # if there is only one item in match_data, generate simplified match? method on the fly # Seems this does not help much # # if match_data.size == 1 # first_item = match_data.first # eigen_class = class << self; self; end # # if first_item.is_a? String # eigen_class.send :define_method, :match? do |method| # method == first_item # end # elsif first_item.is_a? Regexp # eigen_class.send :define_method, :match? do |method| # method =~ first_item # end # else # eigen_class.send :define_method, :match? do |method| # false # end # end # end end |
Instance Method Details
#match?(method) ⇒ Boolean
31 32 33 34 35 36 |
# File 'lib/aspect4r/model/method_matcher.rb', line 31 def match? method @match_data.detect do |item| (item.is_a? String and item == method) or (item.is_a? Regexp and item =~ method) end end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/aspect4r/model/method_matcher.rb', line 38 def to_s @match_data.map {|item| item.inspect }.join ", " end |