osyoyu
osyoyu

Reputation: 115

any short way for (a == 0 || a == foo) in Ruby?

I'm writing some code like this in Ruby:

if very_long_variable_name_that_cant_be_shortened == 0 || very_long_variable_name_that_cant_be_shortened == foo

it's obviously long, and it dosen't look really good. Is there any way to write this shorter?

thanks in advance.

Upvotes: 1

Views: 89

Answers (3)

enrico.bacis
enrico.bacis

Reputation: 31544

You may want to use include?:

>> [0, foo].include? very_long_variable_name_that_cant_be_shortened
=> true

Upvotes: 7

user2219372
user2219372

Reputation: 2455

def helperMethd (f):
    return foo == 0 || f == foo; 

if helperMethd(very_long_variable_name_that_cant_be_shortened):
   bla bla

Upvotes: -1

sawa
sawa

Reputation: 168269

case very_long_variable_name_that_cant_be_shortened
when 0, foo
  ...
end

Upvotes: 4

Related Questions