Class: Uinit::Type::SetOf

Inherits:
Generic show all
Defined in:
lib/uinit/type/set_of.rb

Instance Attribute Summary

Attributes inherited from Generic

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Generic

#initialize, #inspect

Methods inherited from Base

#==, [], #inspect, #is!, #to_s, #trace!, #type_error!

Methods included from Operators

#&, #|

Constructor Details

This class inherits a constructor from Uinit::Type::Generic

Class Method Details

.from(set) ⇒ Object



10
11
12
# File 'lib/uinit/type/set_of.rb', line 10

def self.from(set)
  new(set.first) if from?(set)
end

.from?(set) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/uinit/type/set_of.rb', line 6

def self.from?(set)
  set.is_a?(::Set)
end

Instance Method Details

#check!(value, depth) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/uinit/type/set_of.rb', line 22

def check!(value, depth)
  type_error!("#{value.inspect} must be a Set", depth) unless value.is_a?(::Set)

  value.each_with_index do |val, index|
    type.check!(val, depth + 1)
  rescue Error => e
    trace!(e, "[#{index}]")
  end

  value
end

#is?(value) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/uinit/type/set_of.rb', line 14

def is?(value)
  return false unless value.is_a?(::Set)

  value.all? do |val|
    type.is?(val)
  end
end