How To Create Aliases And Functions For IRB & Rails Console

Posted by Weston Ganger on September 13, 2015

Sometimes you might want to create aliases or functions for your rails console or irb. To do it you just need to create or edit ~/.irbrc

# ~/.irbrc

# If the command already exists and you want to create an alias for it
alias q exit
# Usage: q

# Create a class that contains methods that do work.
class SwissKnife
  def list_tables
# Usage: SwissKnife.list_tables

# OR If you want to create a base level method / command that does a few things at once you create a method on the kernel module.
# ** Note this can be UNSAFE if you overwrite any of the kernels methods
class Kernel
  def tables
# Usage: tables

Related External Links:

Posted in Rails and Tagged with irb console rails alias 

Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts