0.0
No commit activity in last 3 years
No release in over 3 years
Shelike::Pipe offer an operator to behave like the pipe operator of the shell.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Shelike::Pipe

Build Status Code Climate Test Coverage

Shelike::Pipe offer an operator to behave like the pipe operator of the shell.

Installation

Add this line to your application's Gemfile:

gem 'shelike-pipe'

And then execute:

$ bundle

Or install it yourself as:

$ gem install shelike-pipe

Usage

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

Development

After checking out the repo, run bin/setup to install dependencies.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

The gem is available as open source under the terms of the MIT License.