Class: NRSER::Types::Top

Inherits:
Type show all
Defined in:
lib/nrser/types/top.rb

Overview

The top type is the universal type - all values are members.

Constant Summary collapse

NAME =
'*'

Instance Method Summary collapse

Methods inherited from Type

#===, #builtin_inspect, #check, #check!, #default_name, #default_symbolic, #from_data, #has_from_data?, #has_to_data?, #inspect, #intersection, #name, #not, #respond_to?, #test, #to_data, #to_proc, #to_s, #union, #xor

Constructor Details

#initializeTop

Returns a new instance of Top.



31
32
33
34
35
36
37
38
# File 'lib/nrser/types/top.rb', line 31

def initialize
  super name: NAME

  # All types maybe *should* be frozen so they can be used as prop defaults,
  # but this is the first one I ran into in practice, so it's the first one
  # to freeze.
  freeze
end

Instance Method Details

#==(other) ⇒ Boolean

Note:

‘other`’s class must be AnyType exactly - we make no assumptions about anything that has subclasses AnyType.

AnyType instances are all equal.

Parameters:

  • other (*)

    Object to compare to.

Returns:

  • (Boolean)

    ‘true` if `other#class` equals AnyType.



73
74
75
# File 'lib/nrser/types/top.rb', line 73

def == other
  other.class == Top
end

#explainObject



44
45
46
# File 'lib/nrser/types/top.rb', line 44

def explain
  'Top'
end

#from_s(string) ⇒ Object



56
57
58
# File 'lib/nrser/types/top.rb', line 56

def from_s string
  string
end

#has_from_s?Boolean

Returns:



52
53
54
# File 'lib/nrser/types/top.rb', line 52

def has_from_s?
  true
end

#symbolicObject



48
49
50
# File 'lib/nrser/types/top.rb', line 48

def symbolic
  '*' # '⊤'
end

#test?(value) ⇒ Boolean

Returns:



40
41
42
# File 'lib/nrser/types/top.rb', line 40

def test? value
  true
end