What is Binstub?

While I was installing RSpec I run a command here

$bundle binstub rspec-core

I was wondering, what exactly the binstub is?
And why we have to use it?


Binstub is the Binaries require by the executable files. Basically, Binstub prepare the environment around executables before dispatching the call. Ruby might need an extra stuff to their job and here the binstub is use to make sure that the stage is properly set.

let’s go through an example from the Guide

#!/usr/bin/env ruby
require ‘rubygems’

# Prepares the $LOAD_PATH by adding to it lib directories of the gem and
# its dependencies:
gem ‘rspec-core’

# Loads the original executable
load Gem.bin_path(‘rspec-core’, ‘rspec’)

The purpose of every RubyGems binstub is to use RubyGems to prepare the $LOAD_PATH before calling the original executable.


One thought on “What is Binstub?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s