Monday, May 9, 2016

CoffeeScript Substrings

TL;DR


1
2
3
4
5
run_list = [ 'role[flexo]','role[bender]','role[roberto]']

run_list.forEach (result) ->
  role = result.match /\[(\S*)\]/i
  alert(role[1]) # Should yield a message box with "flexo" then "bender" then "roberto"

What I was looking for:

Given a Chef run_list, I needed the name of each role via CoffeeScript. I am working at having hubot tell our deployment processor to run a release. I wanted to help the user find the application they were looking for.

Helpful Links:

Try CoffeeScript - Paste your coffeescript and test it in browser

No comments:

Post a Comment