class DMatch

Public Class Methods

_() click to toggle source
# File lib/destructure/dmatch.rb, line 9
def self._
  Wildcard.instance
end
match(pat, x) click to toggle source
# File lib/destructure/dmatch.rb, line 5
def self.match(pat, x)
  DMatch.new(Env.new).match(pat, x)
end
new(env) click to toggle source
# File lib/destructure/dmatch.rb, line 13
def initialize(env)
  @env = env
end

Public Instance Methods

match(pat, x) click to toggle source
# File lib/destructure/dmatch.rb, line 17
def match(pat, x)
  case
    when pat.is_a?(Wildcard); @env
    when pat.is_a?(Pred) && pat.test(x, @env); @env
    when pat.is_a?(FilterSplat); match_filter_splat(pat, x)
    when pat.is_a?(SelectSplat); match_select_splat(pat, x)
    when pat.is_a?(Splat); match_splat(pat, x)
    when pat.is_a?(Var) && pat.test(x, @env); match_var(pat, x)
    when pat.is_a?(Obj) && pat.test(x, @env) && all_field_patterns_match(pat, x); @env
    when pat.is_a?(String) && pat == x; @env
    when pat.is_a?(Regexp); match_regexp(pat, x)
    when pat.is_a?(Or); match_or(pat, x)
    when hash(pat, x) && all_keys_match(pat, x); @env
    when enumerable(pat, x); match_enumerable(pat, x)
    when pat == x; @env
    else; nil
  end
end