Sha256: a87e2f117c55382a31a908fccd74a2450845eb81ad371727985273b48d05fe9c

Contents?: true

Size: 584 Bytes

Versions: 2

Compression:

Stored size: 584 Bytes

Contents

module Fear
  # @private
  module Utils
    extend self

    def assert_arg_or_block!(method_name, *args)
      unless block_given? ^ !args.empty?
        fail ArgumentError, "##{method_name} accepts either one argument or block"
      end
    end

    def assert_type!(value, *types)
      if types.none? { |type| value.is_a?(type) }
        fail TypeError, "expected `#{value.inspect}` to be of #{types.join(', ')} class"
      end
    end

    def return_or_call_proc(value)
      if value.respond_to?(:call)
        value.call
      else
        value
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fear-0.10.0 lib/fear/utils.rb
fear-0.9.0 lib/fear/utils.rb