Class: RDL::Type::NonNullType

Inherits:
Type show all
Defined in:
lib/rdl/types/non_null.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

#canonical, leq, #nil_type?, #optional?, #to_contract, #vararg?

Constructor Details

#initialize(type) ⇒ NonNullType

Returns a new instance of NonNullType.

Raises:

  • (RuntimeError)


7
8
9
10
11
12
# File 'lib/rdl/types/non_null.rb', line 7

def initialize(type)
  @type = type
  raise RuntimeError, "Singleton types are always non-null" if type.is_a? SingletonType
  raise RuntimeError, "Attempt to create doubly non-null type" if type.is_a? NonNullType
  super()
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/rdl/types/non_null.rb', line 5

def type
  @type
end

Instance Method Details

#<=(other) ⇒ Object



37
38
39
# File 'lib/rdl/types/non_null.rb', line 37

def <=(other)
  return Type.leq(self, other)
end

#==(other) ⇒ Object Also known as: eql?

:nodoc:



18
19
20
21
22
# File 'lib/rdl/types/non_null.rb', line 18

def ==(other) # :nodoc:
  return false if other.nil?
  other = other.canonical
  return (other.instance_of? NonNullType) && (other.type == @type)
end

#copyObject



54
55
56
# File 'lib/rdl/types/non_null.rb', line 54

def copy
  NonNullType.new(@type.copy)
end

#hashObject

:nodoc:



33
34
35
# File 'lib/rdl/types/non_null.rb', line 33

def hash # :nodoc:
  return 157 + @type.hash
end

#instantiate(inst) ⇒ Object



46
47
48
# File 'lib/rdl/types/non_null.rb', line 46

def instantiate(inst)
  return NonNullType.new(@type.instantiate(inst))
end

#match(other) ⇒ Object



26
27
28
29
30
31
# File 'lib/rdl/types/non_null.rb', line 26

def match(other)
  other = other.canonical
  other = other.type if other.instance_of? AnnotatedArgType
  return true if other.instance_of? WildQuery
  return (other.instance_of? NonNullType) && (@type.match(other.type))
end

#member?(obj, *args) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/rdl/types/non_null.rb', line 41

def member?(obj, *args)
  return false if obj.nil?
  @type.member?(obj, *args)
end

#to_sObject



14
15
16
# File 'lib/rdl/types/non_null.rb', line 14

def to_s
  return "!#{@type.to_s}"
end

#widenObject



50
51
52
# File 'lib/rdl/types/non_null.rb', line 50

def widen
  return NonNullType.new(@type.widen)
end