Class: MethodPattern::PatternMatchedFunction::Pattern
- Inherits:
-
Object
- Object
- MethodPattern::PatternMatchedFunction::Pattern
- Defined in:
- lib/method_pattern.rb
Instance Attribute Summary collapse
-
#accepted ⇒ Object
readonly
Returns the value of attribute accepted.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
Instance Method Summary collapse
-
#initialize(accepted, block) ⇒ Pattern
constructor
A new instance of Pattern.
- #match?(args) ⇒ Boolean
- #match_arg?(pattern, arg) ⇒ Boolean
Constructor Details
#initialize(accepted, block) ⇒ Pattern
Returns a new instance of Pattern.
42 43 44 45 |
# File 'lib/method_pattern.rb', line 42 def initialize accepted, block @accepted = accepted @block = block end |
Instance Attribute Details
#accepted ⇒ Object (readonly)
Returns the value of attribute accepted.
40 41 42 |
# File 'lib/method_pattern.rb', line 40 def accepted @accepted end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
40 41 42 |
# File 'lib/method_pattern.rb', line 40 def block @block end |
Instance Method Details
#match?(args) ⇒ Boolean
47 48 49 50 51 52 53 |
# File 'lib/method_pattern.rb', line 47 def match? args @accepted.each_with_index do |pattern, index| return false unless match_arg?(pattern, args[index]) end true end |
#match_arg?(pattern, arg) ⇒ Boolean
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/method_pattern.rb', line 55 def match_arg? pattern, arg case pattern when Hash return false unless arg.is_a? Hash pattern.each do |key, value| return false unless arg.key?(key) && match_arg?(value, arg[key]) end true else pattern === arg end end |