Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pry gem how to reload?

I am using the Pry gem in my Rails console, but the pry flavored rails-console seems to have lost the reload! method for reloading models and stuff.

Here's how I start the pry console

c:\rails\app> pry -r ./config/environment 

Thank You

like image 566
Nik So Avatar asked Sep 08 '11 11:09

Nik So


People also ask

How install gems in pry rails?

Installation. To get started using Pry, simply include the gem 'pry-rails' and 'pry-doc' in your Gemfile, and bundle install! Now every time you boot your rails console you'll have a Pry shell.

How do you open pry in Pokemon Ruby?

We've added pry-doc to access the Ruby core documentation. To start pry, simply type pry after the gem is installed. You can also make it part of your application's dependencies by adding gem "pry" to your application's Gemfile. Installing pry from within the application has its own benefits.

What is GEM pry?

Pry is a runtime developer console and IRB alternative with powerful introspection capabilities. Pry aims to be more than an IRB replacement. It is an attempt to bring REPL driven programming to the Ruby language.


2 Answers

To use reload! like the rails console command, add this code to your .pryrc

# load Rails Console helpers like reload require 'rails/console/app' extend Rails::ConsoleMethods puts 'Rails Console Helpers loaded' 

EDIT== Gem pry-rails already do all of this, much simplier .

like image 78
Rodrigo Dias Avatar answered Sep 22 '22 03:09

Rodrigo Dias


For anyone coming to this question recently: the answer has changed in Rails 3.2, because they've changed how they implement reload! Where in earlier version the irb commands were added as methods to Object, now they are added to IRB::ExtendCommandBundle to avoid polluting the global namespace.

What I do now is (1) in development.rb

silence_warnings do   begin     require 'pry'     IRB = Pry     module Pry::RailsCommands ;end     IRB::ExtendCommandBundle = Pry::RailsCommands   rescue LoadError   end end 

and (2) in .pryrc

if Kernel.const_defined?("Rails") then   require File.join(Rails.root,"config","environment")   require 'rails/console/app'   require 'rails/console/helpers'   Pry::RailsCommands.instance_methods.each do |name|      Pry::Commands.command name.to_s do        Class.new.extend(Pry::RailsCommands).send(name)     end   end end 

Here's the link to the Rails pull request where the change was introduced - https://github.com/rails/rails/pull/3509

like image 43
telent Avatar answered Sep 23 '22 03:09

telent