Sha256: 46fcfffd9f8317fda7da2d371315569911c71c1e79060ce7914207c6291f9a98

Contents?: true

Size: 573 Bytes

Versions: 7

Compression:

Stored size: 573 Bytes

Contents

module Fear
  # @private
  module Utils
    extend self

    def assert_arg_or_block!(method_name, *args)
      unless block_given? ^ args.any?
        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}` 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

7 entries across 7 versions & 1 rubygems

Version Path
fear-0.6.0 lib/fear/utils.rb
fear-0.5.0 lib/fear/utils.rb
fear-0.4.2 lib/fear/utils.rb
fear-0.4.1 lib/fear/utils.rb
fear-0.4.0 lib/fear/utils.rb
fear-0.3.0 lib/fear/utils.rb
fear-0.2.0 lib/fear/utils.rb