Skip to content
Auto-roll-your-own 'RubyFacets'-ish snippets, and automatically deploy them with your project
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib Fixed :copy deployment



my.rb, MyRB, or 'My .RBs' (My rubies), is a system to store your own personal library of ruby snippets and extensions (similar to Ruby Facets, but for your own snippets) on your own computer, and to let you use them transparently in your published coding projects whenever you desire to do so, without even thinking about it.

A lot more of the philosophy behind my.rb is available in the initial blog post by elliottcable.

loading snippets

Before using my.rb, you must configure it - you can do this by running my.rb init, and following the resulting instructions.

Once my.rb is configured, you can load a my.rb file as follows:

my.rb load[~/Desktop/]

A my.rb file must be formatted as a comment block at the top, followed by the snippet code itself. As an example:

# This is just a small snippet that we're providing for you to test my.rb,
# it's pretty awesome!

def Kernel.yay!
  puts 'yay!'

Feel free to copy that into a file, and try loading it.

Once a my.rb is loaded into the library, it's simple to require it in your code:

require 'my.rb/test'

This requires the snippet as a normal ruby library! You're all done, and ready to use your snippet.


Caveat: Some of this, I'm still not too sure about - so specifics here are subject to change.

Now you've been using my.rb while programming, and your code is littered with things along the line of require 'my.rb/autotool', require 'my.rb/tools/rake/send_task', and %w(slugize pathize normalize).each {|m| require "my.rb/string/#{m}"}. Now you want to deploy your package - say, package your library up as a gem for your users, or push your rails app to a server where it will be run as a website. Wait! Your users/server won't have all your favorite my.rb snippets loaded. What do you do?

my.rb::Rake::DeployTask to the rescue. As long as your library/app is required or initialized in some way in your Rakefile.rb, so that all the app files have been loaded into Ruby, you can add a task to your Rakefile that will deploy the my.rb files for you as follows:

require 'myrb/rake/deploytask'

namespace :myrb do

It's that simple. Now, when you run rake myrb:deploy, all the snippets you have used in your code will be copied into your app, ready to be required in on your target computer without the help of my.rb itself.

For this to work in any intelligent / useful way, however, you'll have to tell my.rb what directory your code will want my.rbs in, and you'll have to add that directory to the $LOAD_PATH yourself (in whatever way you find most appropriate). For instance, if you added myapp/lib to the includes path, then you could define the rake task as follows in myapp/Rakefile:

namespace :myrb do do |myrbs|
    myrbs.each :copy, :to => 'lib'

If you have some need to preform more specific magic on each myrb used in your app, you can pass a block to #each:

namespace :myrb do do |myrbs|
    myrbs.each do |myrb|
      puts "This could be some cool stuff I'm doing to each my.rb"
      puts "Or I could just tell you that this my.rb is #{myrb.length} chars."

I'll probably be adding more convenience methods to the task, for instance for Rails, and for the standard Gem structure. Until then, you can probably make do with :copy (-:

Remember: You have to take care of adding the my.rb parent directory to the $LOAD_PATH on your own!

I do this in my projects as follows - this can be placed in the main project file, i.e. ./lib/project_name_.rb:

Dir['../snippets/*'].each {|u| ($:.unshift File.expand_path(u)).uniq!}


At some point, this will be released as a rubygem. I'm lazy, so it may not be soon.

However, in the meantime, it's possible to use it directly from the git repository. Clone the repository from the authoritative source to somewhere on your local drive as follows:

git clone git://

Also, the gem would install the binary automatically - you'll have to do this manually. Create a file in your terminal's $PATH (I use /usr/local/bin/my.rb) named my.rb, and then put something like this in it:

load '/Users/elliottcable/Code/my.rb/bin/my.rb'

Of course, you'll have to replace '/Users/elliottcable/Code/my.rb' in the above with the full path to your my.rb clone. After doing this, you can pretty much use my.rb as directed above.

coming soon

  • smart requirement: my.rb will be smart enough to allow you to use certain kinds of simply-constructed snippets without even requiring them first, and will include them automatically during a rake myrb:deploy
  • my.rb server: you will be able to share your my.rb snippets online, and install snippets directly from the web (think sake -i)
Something went wrong with that request. Please try again.