Class: Regexp

Inherits:
Object show all
Includes:
PatternMatch::Deconstructable
Defined in:
lib/pattern-match/deconstructor.rb

Instance Method Summary collapse

Methods included from PatternMatch::Deconstructable

#call

Instance Method Details

#deconstruct(val) ⇒ Object



55
56
57
58
59
# File 'lib/pattern-match/deconstructor.rb', line 55

def deconstruct(val)
  m = Regexp.new("\\A#{source}\\z", options).match(val.to_s)
  raise PatternMatch::PatternNotMatch unless m
  m.captures.empty? ? [m[0]] : m.captures
end