module RFunk
  class Option
    include Enumerable

    def each(&block)
      return enum_for(:enum) if block.nil?

      enum.each { |v| block.call(v) }
    end
  end

  def Option(value)
    if [Some, None].map { |t| value.is_a?(t) }.any?
      value
    elsif nothing?(value)
      None.instance
    else
      Some.new(value)
    end
  end

  private

  def nothing?(value)
    value.nil? || (value.respond_to?(:empty?) && value.empty?) || value.is_a?(None)
  end
end

module RFunk
  class Option
    include Enumerable

    def each(&block)
      return enum_for(:enum) if block.nil?

      enum.each { |v| block.call(v) }
    end
  end

  def Option(value)
    if [Some, None].map { |t| value.is_a?(t) }.any?
      value
    elsif nothing?(value)
      None.instance
    else
      Some.new(value)
    end
  end

  private

  def nothing?(value)
    value.nil? || (value.respond_to?(:empty?) && value.empty?) || value == None.instance
  end
end

Make sure we check the correct instance.
Make sure we check the correct instance.
