Trick
An attempt to gracefully enhance capabilities of ruby objects.
Installation
Add this line to your application's Gemfile:
gem 'trick'
And then execute:
$ bundle
Or install it yourself as:
$ gem install trick
Usage
Turn something into a proc
module Letter
extend Trick::Proclike
def call(x)
"Letter #{x}"
end
end
Letter.("A") # => "Letter A"
[B", "C"].map(&Letter) # => ["Letter B", "Letter C"]
class RoundedNum
extend Trick::Factory
attr_reader :value
def initialize(number)
@value = number.round
end
end
RoundedNum.(3.333).value # => 3
[5.75, 0.99].map(&RoundedNum).map(&:value) # => [6, 1]
Contributing
- Fork it ( https://github.com/focused/trick/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request