Home

Awesome

logo

Build Status

TrickBag

Assorted Ruby classes, modules, and methods to simplify and enhance your code.

Installation

Add this line to your application's Gemfile:

gem 'trick_bag'

And then execute:

$ bundle

Or install it yourself as:

$ gem install trick_bag

Usage

The best ways to understand the usage are to look at a) the unit tests in the spec directory tree, b) the comments in the source files, and c) the source code itself. That said, here is a summary:

CollectionAccess

Enumerables

Formatters

0x   0  00 07 0E 15 | 1C 23 2A 31 | 38 3F 46 4D | 54 5B 62 69  .....#*18?FMT[bi
0x  10  70 77 7E 85 | 8C 93 9A A1 | A8 AF B6 BD | C4 CB D2 D9  pw~.............
     Index     Decimal        Hex              Binary    Character
     -----     -------        ---              ------    ---------
         0          97         61 x          110 0001 b       a
         1          49         31 x           11 0001 b       1

Functional

These methods provide a shorthand for testing whether or not an object meets an Enumerable of conditional callables.

IO

Meta

Networking

Numeric

Operators

Timing

Validations

Core Types

clone_hash_except - creates a copy of a hash except for the specified keys (this functionality is already included in Rails, but not in Ruby itself)

Why?

This library was born when I was writing a lot of testing tools and data collection and analysis software. At that time I also mentored a team of software testers using Ruby and Cucumber. I saw coding patterns that existed in multiple places, in varying levels of functionality and quality, or sometimes, totally absent when they would have been helpful. Why not implement these patterns once in a shared and tested library?

Some may be very thin layers over the underlying Ruby implementations (e.g. the Elapser class), and their usefulness may be questioned...but in the calling code, the use of these is more intention-revealing, object oriented, and results in more concise calling code.

This gem's files, classes, and methods are for the most part isolated from each other and self-contained. This means that if you like you can easily copy single methods or files from the gem and copy them into your code base to eliminate a dependency on this gem. If you do this, then I suggest you include an attribution to this gem so that future developers can consult it for fixes and enhancements.

Logo

Logo designed and generously contributed by Anhar Ismail (Github: @anharismail, Twitter: @aizenanhar).

Contributing

  1. Fork it
  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 new Pull Request