Overview

Bonk

Why is it called bonk? Because it's a really hard tap.

Bonk is a gem which adds the super cool bonk method to Ruby's Object class. It can be thought of as #map for individual objects or a really hard #tap. The semantics of Bonk are identical to [object].map{|o| ... }.first but without all that tedious mucking about in hyperspace.

Why would you bother using bonk?

  • I dunno, I just like to avoid unnecessary temporary variables.
  • Bonk came about because I wanted to take an ActiveRecord model and send them through a reporting script I wrote that took hashes of information. I tried to do the transformation inline but realized that what I wanted, #map for Object, didn't exist. So I made it using the power of Ruby.

Installation

Add this line to your application's Gemfile:

gem 'bonk'

And then execute:

$ bundle

Or install it yourself as:

$ gem install bonk

Usage

Project.find(42).owner.bonk do |o|
  { :id => o.id, :name => o.realname,
    :problem => "Never updated credit card information." }
#=> {
#     :id => 27,r
#     :name => "Douglas Adams",
#     :problem => "Never updated credit card information"
#   }
end

Achtung! Like #map you can use #bonk for side effects and they will affect the given object. In other words, it isn't duped.

a_sub = NuclearSub.new
#=> #<NuclearSub:0x0000010208e730>
a_sub.bonk{ |sub| sub.generate_missle_launch_codes }
#=> "FIREZEMISSLES"

sub
#=> #<NuclearSub:0x0000010208e730
#     @missle_launch_codes = "FIREZEMISSLES"
#   >

Disclaimer

Don't trust this gem with nuclear submarine controls. I seriously conceived it and wrote it over two train rides after a late night conversation with my none too amused girlfriend.

Contributing

  1. File an issue explaining the semantics of your proposed extension.
  2. Get it approved or make your own simple gem.
  3. Fork it on GitHub or BitBucket.
  4. Create your feature branch.
  5. Commit your changes.
  6. Push to the branch.
  7. Create a new Pull Request.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.