1

Rails 5.2 project; In a controller I have:

  def show
    binding.pry
    @correct_user = false
    some_method or (@correct_user=correct_user) or return
    # -> here the value of @correct_user is false
    # some other code here
  end

some_method evaluates to false; correct_user method evaluates to true here; return is not reached but right after that @correct_user var value is false why is this;

I made another test in 'rails console':

irb(main):001:0> def f
irb(main):002:1>   return false
irb(main):003:1> end
=> :f
irb(main):004:0> def a
irb(main):005:1>   return true
irb(main):006:1> end
=> :a
irb(main):007:0> @t=false
=> false
irb(main):008:0> f or (@t=a) or return
=> true
irb(main):009:0> @t
=> true

So this works as would expect

Jeni
  • 1,088
  • 12
  • 30
  • Does this answer your question? [Difference between "or" and || in Ruby?](https://stackoverflow.com/questions/2083112/difference-between-or-and-in-ruby) – Eyeslandic May 03 '20 at 20:57
  • It does not. I am aware of the difference of these two, and I am using `or` for flow control here, so there's another problem. Thank for the suggestion, though. – Jeni May 04 '20 at 06:32

0 Answers0