Class: NRSER::Types::Equivalent

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

Overview

Type satisfied only by anything ‘#==` it’s #value.

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) ⇒ Equivalent

Returns a new instance of Equivalent.



32
33
34
35
# File 'lib/nrser/types/eqiuvalent.rb', line 32

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

Instance Attribute Details

#valueObject (readonly)

Attributes



30
31
32
# File 'lib/nrser/types/eqiuvalent.rb', line 30

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



48
49
50
51
52
# File 'lib/nrser/types/eqiuvalent.rb', line 48

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

#default_symbolicObject



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

def default_symbolic
  "{ x : #{ value.inspect }==x }"
end

#explainObject



38
39
40
# File 'lib/nrser/types/eqiuvalent.rb', line 38

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

#test?(value) ⇒ Boolean

Returns:



43
44
45
# File 'lib/nrser/types/eqiuvalent.rb', line 43

def test? value
  @value.equal? value
end