Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Defines Kernel#its and Kernel#it that queue and defer method calls, simplifying list comprehension and case statements.
Pull request Compare This branch is 27 commits ahead, 6 commits behind jicksta:master.
Failed to load latest commit information.
spec update to rspec 3, and clean up a bit
.document Initial commit of "its-it" transformation: Renamed, incorporated jewe…
.gitignore fix typo/brain spazz in gitignore, and git rm --cached Gemfile.lock
.rspec update to rspec 3, and clean up a bit
.travis.yml update README, specs & travis for ruby 2.0.0
Gemfile Initial commit of "its-it" transformation: Renamed, incorporated jewe…
LICENSE.txt Initial commit of "its-it" transformation: Renamed, incorporated jewe… Add a Bitdeli badge to README
Rakefile remove beuller development dependency



This gem defines kernel methods its and it that queue and defer method calls. This is handy for list enumeration and case statements.

Gem Version Build Status Dependency Status

List Enumeration

its and it extend the Symbol#to_proc idiom to support chaining multiple methods.

The pure Ruby way to chain methods when enumerating a list would be:

users.collect{|user|}.collect{|contact| contact.last_name}.collect{|name| name.capitalize}

Using Symbol#to_proc, this becomes simpler:


And using its, this becomes becomes simpler still:


Note that its captures arguments and blocks, allowing constructs like this, which will select users whose names include any non-hyphenated word that's more than 10 letters long: /).reject{|word| word =~ /-/}.collect(&:length).max > 10)

it is an alias for its, to use with methods that describe actions rather than posessives. For example:


Case statements

its and it likewise extend Ruby's case statement to support testing arbitrary methods, minimizing the need to create temporary variables and use if-elsif constructs.

In pure Ruby, doing comparisons on computed values would be done something like this:

maxlen = arrays.collect(&size).max
if maxlen > 10000
    "too big"
elsif maxlen < 10
    "too small"

But using it this becomes:

case arrays.collect(&size).max
when it > 1000
    "too big"
when it < 10
    "too small"

Of course method chanining can be used here too:

case users.first
when == "Gimme Cookie" then ...
when > 10 then ...
else ...

Under the hood

The ItsIt::It class uses method_missing to capture and queue up all methods and their arguments, with the exception of :to_proc and :=== (and also excepting :respond_to? :to_proc and :respond_to? :===).

:to_proc returns a proc that will evaluate the method queue on a given argument. :=== takes an argument and evaluates that proc, returning the result.


Install from via

$ gem install "its-it"

or in a Gemfile

gem "its-it"


Works with MRI ruby 1.8.7, 1.9.3, 2.0.0


Release Notes

  • 1.1.1 Remove dependency on BlankSlate

This gem is orignally based on Jay Philips' methodphitamine gem. It has been updated to be compatible with ruby 1.9 and gemspec, added case statement support, renamed its-it, and installed on Unlike methodphitamine, this gem includes only its and it, not the "maybe" monad.

Bitdeli Badge

Something went wrong with that request. Please try again.