True / false judgment based on the condition of each difference with multiple integers

【Overview】

1. Conclusion </ b>

2. How to program </ b>

3. Development environment </ b>

  1. Conclusion

Use the abs method, if </ b>!

  1. How to program

def close_far(a,b,c) #---❶
  x_mar = (a-b).abs
  y_mar = (a-c).abs
  z_mar = (b-c).abs
 if (x_mar == 2 && z_mar >= 3) || (y_mar == 2 && z_mar >= 3) #---❷
   puts "True"
  else
   puts "False"
 end
end

This time I made 3 integers.

❶: The abs method is used to return the absolute value regardless of the positive / negative relationship and assign each to a variable. ❷: This time, "the difference between" a "and" b "is 2 or the difference between" a "and" b "is 2 And"b"When"c”の差が3」Whenしています。下記のようにコーディングするこWhenも可能ですが、上記のように「()When||(OR)When&&(AND)」で一つにまWhenめるこWhenも可能です。

  if x_mar == 2 && z_mar >= 3
    puts "True"
  elsif y_mar == 2 && z_mar >= 3
    puts "True"
  else
    puts "False"
  end

  1. Development environment

Ruby 2.6.5 Rails 6.0.3.3 Visual Studio Code 1.49.2