Class: NRSER::Types::Maybe

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

Overview

Definitions

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

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

Constructor Details

#initialize(type, **options) ⇒ Maybe

Instantiate a new ‘NRSER::Types::Maybe`.



36
37
38
39
# File 'lib/nrser/types/maybe.rb', line 36

def initialize type, **options
  super **options
  @type = NRSER::Types.make type
end

Instance Attribute Details

#typeType (readonly)

The type of all members besides ‘nil`.

Returns:



29
30
31
# File 'lib/nrser/types/maybe.rb', line 29

def type
  @type
end

Instance Method Details

#custom_from_s(string) ⇒ Object



60
61
62
# File 'lib/nrser/types/maybe.rb', line 60

def custom_from_s string
  type.from_s string
end

#explainObject



50
51
52
# File 'lib/nrser/types/maybe.rb', line 50

def explain
  "#{ @type.name }?"
end

#has_from_s?Boolean

Returns:



55
56
57
# File 'lib/nrser/types/maybe.rb', line 55

def has_from_s?
  !@from_s.nil? || type.has_from_s?
end

#test?(value) ⇒ Boolean

Instance Methods

Returns:



45
46
47
# File 'lib/nrser/types/maybe.rb', line 45

def test? value
  value.nil? || @type.test?( value )
end