Shelike::Pipe offer an operator to behave like the pipe operator of the shell.
Add this line to your application's Gemfile:
gem 'shelike-pipe'
And then execute:
$ bundle
Or install it yourself as:
$ gem install shelike-pipe
require 'shelike/pipe'
using Shelike::Pipe
# Can let an object of the left side of a go board apply to the symbol of the right side.
('foo' | :upcase).call # => 'FOO'
# Can apply it for the Method and Proc
require 'json'
('{ "a": 1 }' | JSON.method(:parse)).call # => { "a" => 1 }
('{ "a": 1 }' | ->(json) { JSON.parse(json) }).call # => { "a" => 1 }
# When an argument is necessary, define it with sequence.
(%w(a b c) | :size | [:*, 3]).call # => 9
# Carry out the function that was connected to there by using `^` and catchable an exception.
'{ a: 1 }' | JSON.method(:parse) ^ ->(e) { exception! }
# When an exception occurs, the `^` returns `nil`, and the case except it returns the practice result of the function to there.
'{ a: 1 }' | JSON.method(:parse) ^ ->(e) { exception! } # => nil
'{ "a": 1 }' | JSON.method(:parse) ^ ->(e) { exception! } # => { "a" => 1 }
# When they use `|` and `^` for `nil`, results always become `nil`.
(nil | to_i).call # => nil
-> { nil } ^ :upcase # => nil
After checking out the repo, run bin/setup
to install dependencies.
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Added some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
The gem is available as open source under the terms of the MIT License.