Class: NRSER::Types::Is
Overview
Type satisfied only by it’s exact #value object (identity comparison via ‘#equal?`).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Attributes ========================================================================.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #explain ⇒ Object
-
#initialize(value, **options) ⇒ Is
constructor
A new instance of Is.
- #test?(value) ⇒ Boolean
Methods inherited from Type
#===, #builtin_inspect, #check, #check!, #from_data, #from_s, #has_from_data?, #has_from_s?, #has_to_data?, #inspect, #intersection, #name, #not, #respond_to?, #test, #to_data, #to_s, #union, #xor
Constructor Details
#initialize(value, **options) ⇒ Is
Returns a new instance of Is.
33 34 35 36 |
# File 'lib/nrser/types/is.rb', line 33 def initialize value, ** super ** @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Attributes
31 32 33 |
# File 'lib/nrser/types/is.rb', line 31 def value @value end |
Instance Method Details
#==(other) ⇒ Object
59 60 61 62 63 |
# File 'lib/nrser/types/is.rb', line 59 def == other equal?(other) || ( self.class == other.class && @value == other.value ) end |
#explain ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/nrser/types/is.rb', line 38 def explain case value when Module module_type = if value.is_a?( Class ) then 'Class' else 'Module' end name = if value.anonymous? value.to_s.split( ':' ).last[0...-1] else value.name end "#{ module_type }<#{ name }>" else value.inspect end end |
#test?(value) ⇒ Boolean
55 56 57 |
# File 'lib/nrser/types/is.rb', line 55 def test? value @value.equal? value end |