Rajesh Omanakuttan
Rajesh Omanakuttan

Reputation: 6918

Ruby bundler statement in boot.rb file in Rails App root folder

I found the below given statement in boot.rb file inside the root folder of my Rails Application.

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

Can anyone help me to understand the usage of ENV['BUNDLE_GEMFILE'] and ||= in this context?

Thank you.

Upvotes: 2

Views: 525

Answers (1)

Jan Hančič
Jan Hančič

Reputation: 53931

ENV is a hash. BUNDLE_GEMFILE is an item in that hash. ||= known as "or equals" operator, what it does is checks if ENV['BUNDLE_GEMFILE'] is set, if it is, then it takes the same. But if it isn't, then it assigns whatever the function File.expand_path()returns to ENV['BUNDLE_GEMFILE'].

Upvotes: 5

Related Questions