Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.
/ lightcore Public archive

Lightweight Ruby core extensions

License

Notifications You must be signed in to change notification settings

ankane/lightcore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

About

Lightweight Ruby core extensions

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages