Class: Qrb::Type
- Inherits:
-
Object
- Object
- Qrb::Type
- Defined in:
- lib/qrb/type.rb
Overview
Abstract class for Q type (generators).
Direct Known Subclasses
AdType, AnyType, BuiltinType, RelationType, SeqType, SetType, SubType, TupleType, UnionType
Instance Method Summary collapse
- #dress(*args) ⇒ Object
-
#include?(value) ⇒ Boolean
Check if ‘value` belongs to this type.
-
#initialize(name) ⇒ Type
constructor
A new instance of Type.
- #name ⇒ Object
- #name=(n) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Type
Returns a new instance of Type.
7 8 9 10 11 12 |
# File 'lib/qrb/type.rb', line 7 def initialize(name) unless name.nil? or name.is_a?(String) raise ArgumentError, "String expected for type name, got `#{name}`" end @name = name end |
Instance Method Details
#dress(*args) ⇒ Object
40 41 42 |
# File 'lib/qrb/type.rb', line 40 def dress(*args) raise NotImplementedError, "Missing #{self.class.name}#dress" end |
#include?(value) ⇒ Boolean
Check if ‘value` belongs to this type. Returns true if it’s the case, false otherwise.
For belonging to the type, ‘value` MUST be a valid representation, not an ’approximation’ or some ‘similar’ representation. In particular, returning true means that no dressing is required for using ‘value` as a proper one. Similarly, the method MUST always return true on a value directly obtained through `dress`.
36 37 38 |
# File 'lib/qrb/type.rb', line 36 def include?(value) raise NotImplementedError, "Missing #{self.class.name}#include?" end |
#name ⇒ Object
14 15 16 |
# File 'lib/qrb/type.rb', line 14 def name @name || default_name end |
#name=(n) ⇒ Object
18 19 20 21 |
# File 'lib/qrb/type.rb', line 18 def name=(n) raise Error, "Name already set to `#{@name}`" unless @name.nil? @name = n end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/qrb/type.rb', line 23 def to_s name.to_s end |