Case statment not working with strings

Discussion in 'Ruby' started by Mike Mike, Aug 2, 2008.

  1. Mike Mike

    Mike Mike Guest

    Hello, I have a rather simple case statement:

    case event['event_title']
    when ('Class GroupsPhoto Day' || 'Retake Day' || 'School Group' ||
    'Photo' || 'Staff Group Photo' || 'Staff Group Photo' || 'Teams and
    Clubs' || 'Group Photo Session')
    blah...
    end


    the thing stored in event['event_title'] is a string and the values do
    match my strings (ie should evaluate to true), but the case is never
    evaluating to true.

    any help appreciated, I could always use a big ugle if/elsif
     
    Mike Mike, Aug 2, 2008
    #1
    1. Advertisements

  2. Use a ',' instead of '||'

    Farrel
     
    Farrel Lifson, Aug 2, 2008
    #2
    1. Advertisements

  3. Mike Mike

    Marc Heiler Guest

    Your code also got rid of a few chars! I like it whenever in Ruby I
    successfully apply the rule "less is more" to achieve the same. :)
     
    Marc Heiler, Aug 2, 2008
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.