Class: NRSER::Types::Is

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

Overview

Type satisfied only by it’s exact #value object (identity comparison via ‘#equal?`).

Direct Known Subclasses

Boolean

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

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

Constructor Details

#initialize(value, **options) ⇒ Is

Returns a new instance of Is.



31
32
33
34
# File 'lib/nrser/types/is.rb', line 31

def initialize value, **options
  super **options
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

The exact value for this type.

Returns:



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

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



44
45
46
47
48
# File 'lib/nrser/types/is.rb', line 44

def == other
  equal?(other) ||
  ( self.class.equal?( other.class ) &&
    @value.equal?( other.value ) )
end

#default_symbolicObject



51
52
53
# File 'lib/nrser/types/is.rb', line 51

def default_symbolic
  "{#{ value.inspect }}"
end

#explainObject



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

def explain
  "Is<#{ value.inspect }>"
end

#test?(value) ⇒ Boolean

Returns:



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

def test? value
  @value.equal? value
end