Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4636

Ruby On Rails - Turn If Else Statement Wiith Match? To Case Statement

$
0
0

How do I turn the following if / else statement:

  if /_?town$/.match? name    ['Springfield', 'Shelbyville', 'Kent', 'Carter', 'Benson'].sample  elsif /_?state$/.match? name    ['TX'].sample  else'text'  end

into a case statement in Rails / Ruby?

I tried

  case name  when /_?town$/.match?    ['Springfield', 'Shelbyville', 'Kent', 'Carter', 'Benson'].sample  when /_?state$/.match?    ['TX'].sample  else'text'  end

but I am getting a wrong number of arguments error related to match?


Viewing all articles
Browse latest Browse all 4636

Latest Images

Trending Articles



Latest Images