Sha256: bf076fbaa1f0a392cdc7fbdd15d22af01b659fc60f33fc1b6c0302f6ef336587

Contents?: true

Size: 437 Bytes

Versions: 2

Compression:

Stored size: 437 Bytes

Contents

module Blocks
  class ProcWithArgs
    def self.call(*args)
      return nil unless args.present?
      v = args.shift
      v.is_a?(Proc) ? v.call(*(args[0, v.arity])) : v
    end

    def self.call_each_hash_value(*args)
      options = args.shift.presence || {}
      if options.is_a?(Proc)
        call(options, *args)
      else
        options.inject({}) { |hash, (k, v)| hash[k] = call(v, *args); hash}
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blocks-2.2.1 lib/blocks/proc_with_args.rb
blocks-2.2.0 lib/blocks/proc_with_args.rb