Search code examples
ruby-on-railsrubyparametersaction

Can i check many action params at once


I have actions with many params

test_action(a, b, c, d ,e ,f)

b, c, d ,e ,f may be nil and it's normal. In actions Im need check it on nil

do_somethig if (!b.nil? OR !c.nil? OR !d.nil? OR...)

count params may increase. Please ask me, can I check all params(without first) in one if without OR ?


Solution

  • !b.nil? is basically the same as just b. That means you can rewrite

    do_something if (!b.nil? OR !c.nil? OR !d.nil? OR ...)
    

    as

    do_something if (b || c || d || ...)
    

    Or you could write something like this when you think it is easier to read and understand:

    do_something if [b, c, d, ...].any?