break if status =~ /variable/ wildcard possible in Ruby?

Discussion in 'Ruby' started by Mmcolli00 Mom, Aug 5, 2008.

  1. Can you use a wild card with a variable? I have StrgErrFieldName as a
    variable that will hold a number of possible status ids. I want to
    search on what is in the variable. However =~ only works with strings so
    I have tried putting the variable in inside the '/'. Ruby doesn't like
    it. What do you suggest I do? Please help me out. Thanks. Mom mmcolli00

    while true
    status = ie.status()
    break if status =~//+StrgErrFieldName+//
    Mmcolli00 Mom, Aug 5, 2008
    1. Advertisements

  2. Mmcolli00 Mom

    Heesob Park Guest

    Try this:
    break if status =~/#{StrgErrFieldName}/

    Park Heesob
    Heesob Park, Aug 5, 2008
    1. Advertisements

  3. You are fantastic!
    Mom Mcolli00
    Mmcolli00 Mom, Aug 5, 2008
  4. Use #{var}.

    irb> s=3D"abcdef";
    irb> m=3D"b";
    irb> s =3D~ /#{m}/
    =3D> 1

    regards, Sandor Sz=FCcs
    Sandor Szücs, Aug 6, 2008
    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.