Class: Types::Parser
- Inherits:
- BasicObject
- Defined in:
- lib/types/parser.rb
Overview
Parses type signatures, must be defined at the top level for the purpose of name resolution.
Defined Under Namespace
Modules: TOP
Class Method Summary collapse
-
.const_missing(name) ⇒ Object
Handles missing constants by creating Named types for unknown types.
Instance Method Summary collapse
Class Method Details
Instance Method Details
#parse(signature) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/types/parser.rb', line 19 def parse(signature) # Validate the signature format: unless signature.match?(/\A[a-zA-Z0-9\(\):,_|\s]+\z/) ::Kernel.raise ::ArgumentError, "Invalid type signature: #{signature.inspect}!" end # Replace leading :: with TOP:: to handle absolute type paths normalized_signature = signature.gsub(/(?<=\A|\W)::/, "TOP::") binding = ::Kernel.binding return ::Kernel.eval(normalized_signature, binding) end |