Sha256: a5d8657e0786700d4ad535eba012aaeea42f044c589743e1851c7dd84529f264

Contents?: true

Size: 826 Bytes

Versions: 2

Compression:

Stored size: 826 Bytes

Contents

# frozen_string_literal: true

module LIT
  module Object
    def self.included(object)
      object.define_singleton_method(:Some) { |value| Option::Some.new(value) }
      Utils.const_reset(object, "None", Option::None)
      Utils.const_reset(object, "Some", Class.new(Option::Some))
    end

    # @api public
    # @since 0.1.0
    module Option
      def self.included(object)
        object.define_singleton_method(:Some) { |value| Some.new(value) }
        Utils.const_reset(object, "Some", Class.new(Some))
      end

      None = Class.new

      class Some
        attr_reader :value

        def initialize(value)
          check_type!(value)
          @value = value
        end

        def __value__
          @value
        end

        private

        def check_type!(value); end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
litl-0.1.1 lib/lit/object/option.rb
litl-0.1.0 lib/lit/object/option.rb