4

I tried to edit my ~/.irbrc file and define show_tbls method to fetch the tables I have, because the command is to long , so I tried to make a function for easier use.

require 'hirb' ; Hirb.enable
require 'irb/completion'

def show_tbls
    ActiveRecord::Base.connection.tables
end

When I ran the show_tbls it showed the error as followings

1.9.3-p448 :001 > show_tbls()
NoMethodError: undefined method `show_tbls' for main:Object
        from (irb):1
        from /home/poc/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
        from /home/poc/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
        from /home/poc/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'
1.9.3-p448 :002 > show_tbls
NameError: undefined local variable or method `show_tbls' for main:Object

1 Answer 1

5

define your methods inside Kernel Module

module Kernel
  def show_tbls
    ActiveRecord::Base.connection.tables
  end
end
2
  • excuse me , what file should I modify ?
    – newBike
    Aug 13, 2013 at 8:06
  • @SaidKaldybaev -- what are the potential implications of modifying .irbrc? Are there any?
    – Tass
    Aug 7, 2014 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.