Sha256: 8fadb2864ea6fd3bf4d694e8021c8e123199c9c488880606eae99a6abec67bfa

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

# 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"
require "carbon/tacky"
require "carbon/concrete"

# 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 # => #<Carbon::Concrete::Type Carbon::Boolean>
  # @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

  # 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/core"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
carbon-core-0.1.0 lib/carbon.rb