Question

I am setting up a listen command to grab a string of words in my siriproxy project.

The string can be anything, so the easiest way is to make sure the string starts with a special word. I want to set that word in a variable. That way, I can give the user a way to change it.

Here is what I have:

listen_for /Elvis ([a-z]* ?[a-z]* ?[a-z]* ?[a-z]* ?[a-z]* ?[a-z]*)/i do |event_name|

My command will begin with Elvis, and everything after it becomes the variable event_name.

What if I wanted Elvis to be a variable? I tried this with a big fail.

listen_for /#{myVar} ([a-z]* ?[a-z]* ?[a-z]* ?[a-z]* ?[a-z]* ?[a-z]*)/i do |event_name|
Was it helpful?

Solution

listen_for /#{Regexp.escape myVar} ([a-z]* ?[a-z]* ?[a-z]* ?[a-z]* ?[a-z]* ?[a-z]*)/i do |event_name|

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top