Method: Hash.with_keys

Defined in:
lib/amp/support/support.rb

.with_keys(iterable, value = true) ⇒ Hash

Given a list of key names, and a specified value, we create a hash with those keys all equal to value. Useful for making true/false tables with speedy lookup.

Parameters:

  • iterable (Enumerable)

    any object with Enumerable mixed in can create a hash.

  • value (Object) (defaults to: true)

    (true) the value to assign each key to in the resultant hash

Returns:

  • (Hash)

    a hash with keys from iterable, all set to value



579
580
581
582
583
584
# File 'lib/amp/support/support.rb', line 579

def self.with_keys(iterable, value=true)
  # we try to be functional when it doesn't fuck us over
  # here, the list of keys will never be ridiculous
  # so we go fuctional
  iterable.inject({}) {|h, k| h[k] = value; h }
end