Class: Uinit::Type::Type
Instance Attribute Summary collapse
-
#class_module ⇒ Object
readonly
Returns the value of attribute class_module.
Class Method Summary collapse
Instance Method Summary collapse
- #check!(value, depth) ⇒ Object
-
#initialize(class_module) ⇒ Type
constructor
TODO: Allow to pass Fn.
- #inspect ⇒ Object
- #is?(value) ⇒ Boolean
Methods inherited from Base
#==, [], #is!, #to_s, #trace!, #type_error!
Methods included from Operators
Constructor Details
#initialize(class_module) ⇒ Type
TODO: Allow to pass Fn
15 16 17 18 19 |
# File 'lib/uinit/type/type.rb', line 15 def initialize(class_module) super() @class_module = class_module end |
Instance Attribute Details
#class_module ⇒ Object (readonly)
Returns the value of attribute class_module.
21 22 23 |
# File 'lib/uinit/type/type.rb', line 21 def class_module @class_module end |
Class Method Details
.from(value) ⇒ Object
10 11 12 |
# File 'lib/uinit/type/type.rb', line 10 def self.from(value) new(value) if from?(value) end |
Instance Method Details
#check!(value, depth) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/uinit/type/type.rb', line 29 def check!(value, depth) unless value.is_a?(Class) || value.is_a?(Module) type_error!("#{value.inspect} is not a Class or a Module", depth) end return value if value.ancestors.include?(class_module) type_error!("#{value.inspect} does not extend or include or preprend #{class_module}", depth) end |
#inspect ⇒ Object
39 40 41 |
# File 'lib/uinit/type/type.rb', line 39 def inspect "#{super}[#{class_module.inspect}]" end |