bluejimmy bluejimmy - 11 months ago 54
Ruby Question

What does || between methods mean?

def respond_to?(method, include_private = false)
super || @subject.respond_to?(method, include_private)

is an
operator, so what does
between methods mean?

Will it always call
returns nil then evaluate
because of short-circuiting for the

Edit: I think my question is not a duplicate because I know how the '||' operator work from other programming languages. I know what short-circuiting is. I just have never seen it used with just two methods without if statements involve.


The || operator means the same regardless of how complex the expressions are on each side of it.

A || B means:

  • evaluate A
  • if A == false or A == nil
    • evaluate B
    • return the value of B as the value of the A || B expression
  • otherwise return the value of A as the value of the A || B expression