maybe-chain
Installation
Add this line to your application's Gemfile:
gem 'maybe-chain'
And then execute:
$ bundle
Or install it yourself as:
$ gem install maybe-chain
Usage
m1 = "a".to_maybe.upcase.gsub(/A/, "B")
maybe(m1) do |str|
puts str # => B
end
m2 = nil.to_maybe.upcase.gsub(/A/, "B")
maybe(m2) do |str|
puts str # No Execute
end
maybe(m2, "a") do |str|
puts str # => a
end
m3 = [1,2,3].to_maybe.map {|i| i * 2}.reject {|i| i > 5}
maybe(m3) do |arr|
p arr # => [2, 4]
end
m4 = "a".to_maybe(NoMethodError).upcase.no_method.gsub(/A/, "B")
maybe(m4) do |str|
puts str # => No Execute
end
Contributing
- 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