# encoding: utf-8 # frozen_string_literal: true require "ice_nine" require "ice_nine/core_ext/object" require "base58" require "digest/sha2" require "concurrent" require "llvm" require "llvm/core" require "carbon/version" # Carbon. The language. module Carbon # rubocop:disable Style/MethodName # Creates a type. This uses {Carbon::Concrete::Type}, and assumes that the # parameter must be a string to be parsed. # # @api public # @example # type = Carbon::Type("Carbon::Boolean") # type # => # # @param string [::String] The string to parse. # @return [Carbon::Concrete::Type] The resulting type. def self.Type(string) Carbon::Concrete::Type.from(string) end # rubocop:enable Style/MethodName # Hashes a given string into the format used by Carbon. The format is a # Base58-encoded SHA256 digest. # # @api semipublic # @example # Carbon.hash("") # => "gjNT5GbSC-81KmUPncw-hzQAGV3GU-eAXafmkMP-Bw2GMHWM" # @param string [::String] The string to hash. # @return [::String] The hashed string. def self.hash(string) digest = Digest::SHA2.hexdigest(string).hex encoded = Base58.encode(digest) encoded.scan(/.{1,9}/).join("-").freeze end require "carbon/concrete" # A Boolean type for Carbon. This is used as a handy shortcut. # # @api private # @return [Carbon::Concrete::Type] Boolean = Carbon::Type("Carbon::Boolean") require "carbon/tacky" require "carbon/core" end