Class: Kind::Any

Inherits:
Object
  • Object
show all
Defined in:
lib/kind/any.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Any

Returns a new instance of Any.



11
12
13
14
15
# File 'lib/kind/any.rb', line 11

def initialize(*args)
  array = args.size == 1 ? args[0] : args

  @values = Kind.of(FilledList, array, expected: 'filled array or set')
end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



9
10
11
# File 'lib/kind/any.rb', line 9

def values
  @values
end

Instance Method Details

#===(value) ⇒ Object



17
18
19
# File 'lib/kind/any.rb', line 17

def ===(value)
  @values.include?(value)
end

#[](value, label: nil) ⇒ Object



21
22
23
# File 'lib/kind/any.rb', line 21

def [](value, label: nil)
  STRICT.object_is_a(self, value, label)
end

#nameObject Also known as: inspect



29
30
31
32
33
34
35
36
37
38
# File 'lib/kind/any.rb', line 29

def name
  str = @values.inspect

  if @values.is_a?(::Set)
    str.sub!(/\A#<Set: /, '')
    str.chomp!('>')
  end

  "Kind::Any#{str}"
end

#|(another_kind) ⇒ Object



25
26
27
# File 'lib/kind/any.rb', line 25

def |(another_kind)
  UnionType[self] | another_kind
end