Project

lightcore

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Lightweight Ruby core extensions
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.5
>= 0
 Project Readme

Lightcore

Lightweight Ruby core extensions

  • count_by
  • hash_map
  • mapk, mapk!
  • mapv, mapv!
  • to_b

Plays nicely with the Ruby core and ActiveSupport.

Get Started

Add this line to your application’s Gemfile:

gem 'lightcore'

Methods

count_by

Groups and counts an array

users.count_by(&:country_code)
# {
#   "US" => 5,
#   "DE" => 2
# }

hash_map

Converts an array of key-value pairs to a hash

users.hash_map{|u| [u.id, u.name] }
# {
#   1 => "Nick",
#   2 => "Andrew"
# }

mapk

Updates the keys of a hash

hash.mapk{|k| k.to_sym }

mapk! updates the original hash

mapv

Updates the values of a hash

hash.mapv{|v| v[0] }

mapv! updates the original hash

to_b

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

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help: