Class: Code::Type

Inherits:
Object show all
Defined in:
lib/code/type.rb,
lib/code/type/or.rb,
lib/code/type/sig.rb,
lib/code/type/hash.rb,
lib/code/type/maybe.rb,
lib/code/type/repeat.rb

Direct Known Subclasses

Hash, Maybe, Or, Repeat

Defined Under Namespace

Classes: Hash, Maybe, Or, Repeat, Sig

Instance Method Summary collapse

Instance Method Details

#max_arguments_of(clazz) ⇒ Object



29
30
31
# File 'lib/code/type.rb', line 29

def max_arguments_of(clazz)
  clazz.is_a?(Type) ? clazz.max_arguments : 1
end

#maybeObject



5
6
7
# File 'lib/code/type.rb', line 5

def maybe
  Maybe.new(self)
end

#min_arguments_of(clazz) ⇒ Object



25
26
27
# File 'lib/code/type.rb', line 25

def min_arguments_of(clazz)
  clazz.is_a?(Type) ? clazz.min_arguments : 1
end

#repeat(minimum = 0, maximum = nil) ⇒ Object



9
10
11
# File 'lib/code/type.rb', line 9

def repeat(minimum = 0, maximum = nil)
  Repeat.new(self, minimum:, maximum:)
end

#valid?(_argument) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/code/type.rb', line 17

def valid?(_argument)
  false
end

#valid_for?(expected:, actual:) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/code/type.rb', line 21

def valid_for?(expected:, actual:)
  expected.is_a?(Type) ? expected.valid?(actual) : actual.is_a?(expected)
end

#|(other) ⇒ Object



13
14
15
# File 'lib/code/type.rb', line 13

def |(other)
  Or.new(self, other)
end