Class: DMatch::Obj

Inherits:
Object show all
Includes:
Predicated
Defined in:
lib/destructure/types.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Predicated

#test

Constructor Details

#initialize(fields = {}, &pred) ⇒ Obj

Returns a new instance of Obj.



59
60
61
62
# File 'lib/destructure/types.rb', line 59

def initialize(fields={}, &pred)
  @fields = fields
  self.pred = pred
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



57
58
59
# File 'lib/destructure/types.rb', line 57

def fields
  @fields
end

Class Method Details

.of_type(klass, fields = {}, &pred) ⇒ Object



64
65
66
# File 'lib/destructure/types.rb', line 64

def self.of_type(klass, fields={}, &pred)
  Obj.new(fields) {|x| x.is_a?(klass) && (!pred || pred.call(x))}
end