Or = for a constant

Hello,

I want to set a constant to be the value from an env variable or if that
is not there set it to the current directory.

So, I am doing this:

WORKINGDIR = ENV[‘CCNetWorkingDirectory’] ? ENV[‘CCNetWorkingDirectory’]
: “.”

But it doesn’t seem very Ruby/DRY like.

Is there a better way to do this?

Sorry for the basic question… but 5 chapters into Why’s guide and I
haven’t got to a solution yet.

BOb

Hi –

On Fri, 5 Dec 2008, Bob Archer wrote:

Is there a better way to do this?

WORKINGDIR = ENV[‘CCNetWorkingDirectory’] || “.”

David

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs