Reputation: 115
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
Reputation: 31544
You may want to use include?
:
>> [0, foo].include? very_long_variable_name_that_cant_be_shortened
=> true
Upvotes: 7
Reputation: 2455
def helperMethd (f):
return foo == 0 || f == foo;
if helperMethd(very_long_variable_name_that_cant_be_shortened):
bla bla
Upvotes: -1
Reputation: 168269
case very_long_variable_name_that_cant_be_shortened
when 0, foo
...
end
Upvotes: 4