Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Allows you to bind procs to instances of classes

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Rakefile
Octocat-spinner-32 bindable_block.gemspec


instance_exec can't take block arguments. Get around that with BindableProc

require 'bindable_block'

User = :name
greeter = { "Welcome, #{name}" }
greeter.bind( "Josh").call # => "Welcome, Josh"

Here is an example.

Where the abstraction leaks

Bindable block does something that isn't possible in Ruby. It does this with black magick. Unfortunately, that abstraction will leak in the case of return statements. Return statements in blocks will return you from the containing method.

def meth { return 1 }.call

meth # => 1

Return statements in lambdas will return you from the lambda.

def meth
  lambda { return 1 }.call

meth # => 2

You would expect a bindable block to continue to behave like the former example, but it will actually behave like the latter example.

At present, I can only think of two ways to fix this:

1) It might be possible to rewrite the AST with ripper. 2) It is probably possible to write this in C.

Neither of these are high on my priority list.


Add this line to your application's Gemfile:

gem 'bindable_block'

And then execute:

$ bundle

Or install it yourself as:

$ gem install bindable_block
Something went wrong with that request. Please try again.