Class: Cry::Codegen::Interface::Type
- Inherits:
-
String
- Object
- String
- Cry::Codegen::Interface::Type
- Defined in:
- lib/cry/codegen/interface.rb
Constant Summary collapse
- VALID_CRYSTAL_TYPES =
Why Symbol is not included in VALID_CRYSTAL_TYPES? Because there is no way to convert String to Symbol. Symbols are translated to numbers in compile time. Use String instead of Symbol. See:
['Int8', 'Int8*', 'Array(Int8)', 'UInt8', 'UInt8*', 'Array(UInt8)', 'Int16', 'Int16*', 'Array(Int16)', 'UInt16', 'UInt16*', 'Array(UInt16)', 'Int32', 'Int32*', 'Array(Int32)', 'UInt32', 'UInt32*', 'Array(UInt32)', 'Int64', 'Int64*', 'Array(Int64)', 'UInt64', 'UInt64*', 'Array(UInt64)', 'Float32', 'Float32*', 'Array(Float32)', 'Float64', 'Float64*', 'Array(Float64)', 'String', 'Void'].freeze
Instance Method Summary collapse
-
#initialize(type_name) ⇒ Type
constructor
A new instance of Type.
- #inner ⇒ Object
- #inner_pointer ⇒ Object
- #is_array? ⇒ Boolean
- #is_pointer? ⇒ Boolean
Constructor Details
#initialize(type_name) ⇒ Type
Returns a new instance of Type.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cry/codegen/interface.rb', line 25 def initialize(type_name) case type_name when String raise "Invalid type name: #{type_name}" unless VALID_CRYSTAL_TYPES.include?(type_name) when Symbol type_name = type_name.to_s else raise "Type name must be a String or Symbol (got #{type_name.class})" end super(type_name) end |
Instance Method Details
#inner ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/cry/codegen/interface.rb', line 46 def inner if is_pointer? then delete_suffix('*') elsif is_array? then delete_prefix('Array(').delete_suffix(')') else self end end |
#inner_pointer ⇒ Object
54 55 56 |
# File 'lib/cry/codegen/interface.rb', line 54 def inner_pointer "#{inner}*" end |
#is_array? ⇒ Boolean
42 43 44 |
# File 'lib/cry/codegen/interface.rb', line 42 def is_array? start_with?('Array(') && end_with?(')') end |
#is_pointer? ⇒ Boolean
38 39 40 |
# File 'lib/cry/codegen/interface.rb', line 38 def is_pointer? end_with?('*') end |