简体   繁体   中英

strange behaviour - irb and rails console

The irb is giving true at first and then false always for the command require rails .

The rails console is giving false always.

How's this happening?

Please see below cmd-

~/Workspaces/eclipse/image_cropper_ws/image_cropper$ irb

1.9.2-p180 :001 > require 'rails'
=> true 
1.9.2-p180 :002 > require 'rails'
=> false 
1.9.2-p180 :003 > exit



~/Workspaces/eclipse/image_cropper_ws/image_cropper$ rails console
Loading development environment (Rails 3.2.8)

1.9.2-p180 :001 > require 'rails'
=> false 
1.9.2-p180 :002 > require 'rails'
=> false 

require returns false when what you're trying to require is already loaded - the first time you require 'rails' , it's not loaded, and require returns true.
The second time you require 'rails' , it is already loaded and require returns false.

Rails is always loaded in the rails console.

Check the docs for require , it states

Loads the given name, returning true if successful and false if the feature is already loaded.

So the first time you call require in irb it loads and returns true. The second time it is already loaded so it returns false.

When you call rails c it loads irb with your rails environment so it must have already required rails

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM