Skip to content

Latest commit

 

History

History
41 lines (25 loc) · 2.73 KB

2013-12-23.md

File metadata and controls

41 lines (25 loc) · 2.73 KB

emil

pry --gem opens a pry session with ./lib added to $LOAD_PATH and 'require's the gem. A good shortcut while working on gems and you want a quick console with the gem loaded.

amitava

rcm is a utility to easily manage dotfiles. There is no need to manually create symlinks or maintain an install script. It even allows to use multiple dotfiles directly (host specific, multiple source dir etc). One really nice feature is the ability to track which dotfiles are symlinked.

hemant

Similar to pry --gem tip is, ruby has a switch called -s which can be used for running binaries which are present in local directory. for example, if you are working on bundler and want to run bundle command with local version of bundler rather than one installed globally you can use:

ruby -S ./bin/bundle -I ./lib/ install

Especially useful while developing gems which has binary files.

For simple scripts there isn't much difference between ruby bin/bundle and ruby -S ./bin/bundle. But to list out things:

a. ruby -S allows you to ignore #!/usr/bin/env ruby line and even if current version of ruby is X. using ruby -S one can run scripts with different version of Ruby. In fact thats how most of jruby scripts are run in production, if not using rvm.

b. I think biggest difference between ruby -S and ruby foo is, ruby -S allows corresponding ruby to change PATH and search the program specified from modified PATH. For example -

  1. Install JRuby. and just make an alias to jruby

     alias jruby=$HOME/jruby-path/bin/jruby:$PATH:.
    
  2. Now any command run with jruby -S should actually use JRUBY_HOME/bin binaries, even though JRUBY_HOME/bin was not in original shell's PATH. For example, jruby ships with a command called ast. which if you run via ast will throw error "Command not found". But if you run it via jruby -S ast it actually works. Also unlike jruby ./JRUBY_HOME/bin/ast with -S flag you did not had to specify full path to ast script. It automatically picked it up.

  3. The reason ast command was picked from proper location even if full path to it was not specified in jruby -S ast command is because when used with -S - RUBYPATH environment variable allows PATH to be modified before running the command. From docs:

"RUBYPATH - When used with the -S switch on the command line, the paths listed in RUBYPATH will be added to the paths searched when looking for Ruby scripts. The paths in RUBYPATH precede the paths listed in PATH."

  1. Using ruby -S also kind of helps in environments where shebang lines are not correctly interpreted. ruby -S also takes really well whitespaces etc present in PATH when starting new command and as such is more portable!