Mohamed El Mahallawy
Mohamed El Mahallawy

Reputation: 13842

if statement of many things ruby

Simply question but trying to see if there is an easier way:

if @integration.provider == "hello" || @integration.provider == "hi"
  #block of code
end

Is there an easier way to just have "hello" || "hi" ?

Upvotes: 0

Views: 42

Answers (1)

Dylan
Dylan

Reputation: 1402

Enumerable#include? will determine if a value is found in a given array.

if ["hello", "hi"].include? @integration.provider

Alternative syntax for strings:

if %w(hello hi).include? @integration.provider

Upvotes: 6

Related Questions