Project

rekey

0.02
No release in over 3 years
Low commit activity in last 3 years
Reformat Enumerables into Hashes, using derived keys / values
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 10

Runtime

~> 1.1
 Project Readme

Rekey

Gem codecov

Reformat Enumerables into Hashes, using derived keys / values

Install

gem install rekey

Usage

require "rekey"

# key a list of records by id
[
  { id: 1, name: "alice", age: 30},
  { id: 2, name: "bob", age: 24},
  { id: 3, name: "charlie", age: 88},
].rekey :id
=> {
  1 => { id: 1, name: "alice", age: 30},
  2 => { id: 2, name: "bob", age: 24},
  3 => { id: 3, name: "charlie", age: 88},
}


# create an id => value map from a list of records
[
  { id: 1, name: "alice", age: 30},
  { id: 2, name: "bob", age: 24},
  { id: 3, name: "charlie", age: 88},
].rekey :id, :name
=> {
  1 => "alice",
  2 => "bob",
  3 => "charlie"
}


# or use blocks
[ 2, 4, 6 ].rekey {|v| v / 2}
=> {
  1 => 2,
  2 => 4,
  3 => 6
}