ruby if string contains -


with following code, expect bravo if file name 123456.txt.

if file_name#=~ ('.+(775|776|777|778)\.txt')   @outputs['answer'] = 'alpha' elsif file_name#=~ (.+(456|546)\.txt)   @outputs['answer'] = 'bravo' 

but answer results in alpha. missing here?

# defines start of comment. operator test against regexes =~, not #=~.

if file_name 

will case being picked, unless file_name false or nil, hence why 'alpha'.


also literal syntax create regexes //, not (''):

if file_name =~ /.+(775|776|777|778)\.txt/ 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -