Class: Uinit::Type::Base

Inherits:
Object
  • Object
show all
Includes:
Operators
Defined in:
lib/uinit/type/base.rb

Direct Known Subclasses

Check, Composition, Const, Fn, Generic, HashOf, Impl, Instance

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Operators

#&, #|

Class Method Details

.[]Object



16
17
18
# File 'lib/uinit/type/base.rb', line 16

def self.[](...)
  new(...)
end

.from(type) ⇒ Object



12
13
14
# File 'lib/uinit/type/base.rb', line 12

def self.from(type)
  type if from?(type)
end

.from?(type) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/uinit/type/base.rb', line 8

def self.from?(type)
  type.is_a?(Base)
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
# File 'lib/uinit/type/base.rb', line 38

def ==(other)
  inspect == other.inspect
end

#inspectObject



30
31
32
# File 'lib/uinit/type/base.rb', line 30

def inspect
  "$#{self.class.name.split('::').last}"
end

#is!(value) ⇒ Object



42
43
44
45
46
47
# File 'lib/uinit/type/base.rb', line 42

def is!(value)
  check!(value, 0)
rescue Error => e
  e.value = value
  raise
end

#to_sObject



34
35
36
# File 'lib/uinit/type/base.rb', line 34

def to_s
  inspect
end

#trace!(error, trace) ⇒ Object



24
25
26
27
28
# File 'lib/uinit/type/base.rb', line 24

def trace!(error, trace)
  error.trace(self, trace)

  raise error
end

#type_error!(message, depth, trace = []) ⇒ Object

Raises:



20
21
22
# File 'lib/uinit/type/base.rb', line 20

def type_error!(message, depth, trace = [])
  raise Error.new(message.to_s, [self], depth, trace)
end