dalexj / hash_shortcut

Provides a block shortcut for ruby hash access

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hash_shortcut

This gem adds in a to_proc method to arrays for the purpose of accessing hash values through a block shortcut, very similar to the &:symbol implementation

Download

gem install hash_shortcut

Examples

data = [{ a: 3 }, { a: 2 }, { a: 4 }]

# plain ruby
data.map { |obj| obj[:a] }

# with hash_shortcut
data.map &[:a]

# => [3, 2, 4]

About

Provides a block shortcut for ruby hash access


Languages

Language:Ruby 100.0%