Class: Finitio::BuiltinType
- Defined in:
- lib/finitio/type/builtin_type.rb
Overview
A BuiltinType generator allows capuring an information type to a type of the host language, here a Ruby class. For instance,
Int := BuiltinType(ruby.Fixnum)
The set of values captured by the information type is the same set of values that can be represented by the host type. In the example, ‘Int` captures the same set of numbers as ruby’s Fixnum.
The ruby class is used as concrete representation of the information type. In the example:
R(Int) = Fixnum
Accordingly, the ‘dress` transformation function has the following signature:
dress :: Alpha -> Int throws TypeError
dress :: Object -> Fixnum throws TypeError
Constant Summary
Constants included from Metadata
Instance Attribute Summary collapse
-
#ruby_type ⇒ Object
(also: #representator)
readonly
Returns the value of attribute ruby_type.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #default_name ⇒ Object
-
#dress(value, handler = DressHelper.new) ⇒ Object
Check that ‘value` is a valid instance of `ruby_type` through `===` or raise an error.
- #hash ⇒ Object
- #include?(value) ⇒ Boolean
-
#initialize(ruby_type, name = nil, metadata = nil) ⇒ BuiltinType
constructor
A new instance of BuiltinType.
Methods inherited from Type
#anonymous?, #name, #name=, #named?, #to_s
Methods included from Metadata
#metadata, #metadata=, #metadata?
Constructor Details
#initialize(ruby_type, name = nil, metadata = nil) ⇒ BuiltinType
Returns a new instance of BuiltinType.
24 25 26 27 |
# File 'lib/finitio/type/builtin_type.rb', line 24 def initialize(ruby_type, name = nil, = nil) super(name, ) @ruby_type = ruby_type end |
Instance Attribute Details
#ruby_type ⇒ Object (readonly) Also known as: representator
Returns the value of attribute ruby_type.
28 29 30 |
# File 'lib/finitio/type/builtin_type.rb', line 28 def ruby_type @ruby_type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
47 48 49 |
# File 'lib/finitio/type/builtin_type.rb', line 47 def ==(other) super || (other.is_a?(BuiltinType) && other.ruby_type==ruby_type) end |
#default_name ⇒ Object
32 33 34 |
# File 'lib/finitio/type/builtin_type.rb', line 32 def default_name @ruby_type.name.to_s end |
#dress(value, handler = DressHelper.new) ⇒ Object
Check that ‘value` is a valid instance of `ruby_type` through `===` or raise an error.
42 43 44 45 |
# File 'lib/finitio/type/builtin_type.rb', line 42 def dress(value, handler = DressHelper.new) handler.failed!(self, value) unless ruby_type===value value end |
#hash ⇒ Object
52 53 54 |
# File 'lib/finitio/type/builtin_type.rb', line 52 def hash self.class.hash ^ ruby_type.hash end |
#include?(value) ⇒ Boolean
36 37 38 |
# File 'lib/finitio/type/builtin_type.rb', line 36 def include?(value) ruby_type === value end |