Class: DMatch::FilterSplat

Inherits:
Splat show all
Defined in:
lib/destructure/types.rb

Overview

experimental

Instance Attribute Summary collapse

Attributes inherited from Var

#name

Instance Method Summary collapse

Methods included from Predicated

#test

Constructor Details

#initialize(name = nil, pattern) ⇒ FilterSplat

Returns a new instance of FilterSplat.



33
34
35
36
37
# File 'lib/destructure/types.rb', line 33

def initialize(name=nil, pattern)
  super(name)
  @pattern = pattern
  validate_pattern
end

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



31
32
33
# File 'lib/destructure/types.rb', line 31

def pattern
  @pattern
end

Instance Method Details

#validate_patternObject



39
40
41
# File 'lib/destructure/types.rb', line 39

def validate_pattern
  raise 'FilterSplat pattern cannot contain variables' if @pattern.flatten.any?{|p| p.is_a?(Var)}
end