Lightweight Ruby core extensions
- count_by
- hash_map
- mapk, mapk!
- mapv, mapv!
- to_b
Plays nicely with the Ruby core and ActiveSupport.
Add this line to your application’s Gemfile:
gem 'lightcore'
Groups and counts an array
users.count_by(&:country_code)
# {
# "US" => 5,
# "DE" => 2
# }
Converts an array of key-value pairs to a hash
users.hash_map{|u| [u.id, u.name] }
# {
# 1 => "Nick",
# 2 => "Andrew"
# }
Updates the keys of a hash
hash.mapk{|k| k.to_sym }
mapk!
updates the original hash
Updates the values of a hash
hash.mapv{|v| v[0] }
mapv!
updates the original hash
Converts an object to a boolean - works great with strings
"true".to_b # true
"hi".to_b # true
"false".to_b # false
"f".to_b # false
nil.to_b # false
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features