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

  1. Fork it ( https://github.com/focused/trick/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request