Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vlad-shatskyi/uberscore
A gem that makes your Ruby blocks more concise.
https://github.com/vlad-shatskyi/uberscore
Last synced: about 2 months ago
JSON representation
A gem that makes your Ruby blocks more concise.
- Host: GitHub
- URL: https://github.com/vlad-shatskyi/uberscore
- Owner: vlad-shatskyi
- License: mit
- Created: 2015-07-27T20:50:36.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-04-03T12:45:20.000Z (over 8 years ago)
- Last Synced: 2024-05-18T18:21:15.378Z (4 months ago)
- Language: Ruby
- Homepage: https://github.com/shockone/uberscore
- Size: 124 KB
- Stars: 85
- Watchers: 3
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Uberscore
Born to make your Ruby blocks more concise.
```ruby
# Chain method calls.
%w[0x 0d ea].map { |element| element.hex.divmod(13)[1] == 0 } # Without Uberscore
%w[0x 0d ea].map(&_.hex.divmod(13)[1] == 0) # With Uberscore# Use class methods.
[Array, Hash].map { |a_class| a_class.new(4) }
[Array, Hash].map(&_.new(4))# Nest.
[[2, 3]].map { |array| array.map { |element| element * 2 } }
[[2, 3]].map(&_.map(&_ * 2))# Subscript.
[{ name: "foo" }, { name: "bar" }].map { |hash| hash[:name] }
[{ name: "foo" }, { name: "bar" }].map(&_[:name])
```# Name Conflict
The method name `_` conflicts with the last expression shortcut in Pry and IRB.
If you wish to name the method differently, define the constant `UBERSCORE_METHOD_NAME`
before requiring the gem.```ruby
UBERSCORE_METHOD_NAME = :it # or any other name.require "uberscore"
[{ name: "foo" }, { name: "bar" }].map(&it[:name])
```## Installation
Add this line to your application's Gemfile:
gem 'uberscore'
And then execute:
$ bundle
Or install it yourself as:
$ gem install uberscore
## License
MIT