Class: NRSER::Types::IsA
Overview
Instance Attribute Summary collapse
-
#mod ⇒ Object
readonly
Returns the value of attribute mod.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#custom_from_data(data) ⇒ Object
Forwards to ‘mod.from_data`.
- #explain ⇒ Object
-
#has_from_data? ⇒ Boolean
Overrides Type#has_from_data? to respond ‘true` when there is a instance-specific `@from_data` or the #mod responds to `.from_data`.
- #init_from_data? ⇒ Boolean
-
#initialize(mod, init_from_data: false, **options) ⇒ IsA
constructor
A new instance of IsA.
- #test?(value) ⇒ Boolean
Methods inherited from Type
#===, #builtin_inspect, #check, #check!, #default_name, #default_symbolic, #from_data, #from_s, #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(mod, init_from_data: false, **options) ⇒ IsA
Returns a new instance of IsA.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/nrser/types/is_a.rb', line 35 def initialize mod, init_from_data: false, ** unless mod.is_a?( Module ) raise ArgumentError, "`mod` argument must be a Module (inc. Class), " \ "received #{ mod.inspect }" end super ** @init_from_data = !!init_from_data @mod = mod end |
Instance Attribute Details
#mod ⇒ Object (readonly)
Returns the value of attribute mod.
33 34 35 |
# File 'lib/nrser/types/is_a.rb', line 33 def mod @mod end |
Instance Method Details
#==(other) ⇒ Object
93 94 95 96 97 |
# File 'lib/nrser/types/is_a.rb', line 93 def == other equal?( other ) || ( self.class == other.class && self.mod == other.mod ) end |
#custom_from_data(data) ⇒ Object
Forwards to ‘mod.from_data`.
71 72 73 74 75 76 77 |
# File 'lib/nrser/types/is_a.rb', line 71 def custom_from_data data if init_from_data? mod.new data else mod.from_data data end end |
#explain ⇒ Object
50 51 52 |
# File 'lib/nrser/types/is_a.rb', line 50 def explain mod.safe_name end |
#has_from_data? ⇒ Boolean
Overrides Type#has_from_data? to respond ‘true` when there is a instance-specific `@from_data` or the #mod responds to `.from_data`.
86 87 88 89 90 |
# File 'lib/nrser/types/is_a.rb', line 86 def has_from_data? @from_data || init_from_data? || mod.respond_to?( :from_data ) end |
#init_from_data? ⇒ Boolean
60 61 62 |
# File 'lib/nrser/types/is_a.rb', line 60 def init_from_data? @init_from_data end |
#test?(value) ⇒ Boolean
55 56 57 |
# File 'lib/nrser/types/is_a.rb', line 55 def test? value value.is_a? mod end |