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.
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.
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 -
-
Install JRuby. and just make an alias to jruby
alias jruby=$HOME/jruby-path/bin/jruby:$PATH:.
-
Now any command run with
jruby -S
should actually useJRUBY_HOME/bin
binaries, even thoughJRUBY_HOME/bin
was not in original shell's PATH. For example, jruby ships with a command calledast
. which if you run viaast
will throw error "Command not found". But if you run it viajruby -S ast
it actually works. Also unlikejruby ./JRUBY_HOME/bin/ast
with-S
flag you did not had to specify full path toast
script. It automatically picked it up. -
The reason
ast
command was picked from proper location even if full path to it was not specified injruby -S ast
command is because when used with-S
-RUBYPATH
environment variable allowsPATH
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."
- 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 inPATH
when starting new command and as such is more portable!