class ActivePattern::PatternObject

Public Class Methods

new(context_class, pattern) click to toggle source
# File lib/active_pattern/pattern_object.rb, line 3
def initialize(context_class, pattern)
  @context_class = context_class
  @pattern = pattern
end

Public Instance Methods

===(other) click to toggle source
# File lib/active_pattern/pattern_object.rb, line 8
def ===(other)
  return false unless @context_class === other

  match_result = other.instance_eval(&@pattern)
  case match_result
  in Array | Hash
    $_ACTIVE_PATTERN_MATCHES = match_result
    true
  else
    $_ACTIVE_PATTERN_MATCHES = nil
    match_result
  end
rescue NoMatchingPatternError
  false
end