Gabriel Baker
Gabriel Baker

Reputation: 1219

coffeescript split string or default in one line

I'm currently checking for an environment variable, which may or may not exist, and assigning that to a variable or setting a default if it doesn't exist. I'm then splitting the string in a different line to get an array. I'm wondering if this can be done in a simple one liner (without having to double check the env var)

Currently doing:

deploy_rooms = process.env['HUBOT_DPLOY_ROOMS'] || "deployments"
deploy_rooms = deploy_rooms.split ','

could do this

deploy_rooms = (process.env['HUBOT_DPLOY_ROOMS'] || "deployments").split ','

but wondering if there's a nicer way?

Upvotes: 2

Views: 978

Answers (1)

Gabriel Baker
Gabriel Baker

Reputation: 1219

yeh just do this

deploy_rooms = (process.env['HUBOT_DPLOY_ROOMS'] || "deployments").split ','

Upvotes: 1

Related Questions