Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what kind of syntax is on the right side of this equation?

Tags:

ruby

def is_fibonacci?(i,a=0, b=1)
  i > a ? is_fibonacci?(i, a + b, a) : a <= i if true
end

I've never seen a <= i if true

it seems to say "return true if a <=i and return false otherwise"

But are there more examples of this strange order I can look at?

like image 543
dwilbank Avatar asked Oct 20 '22 18:10

dwilbank


1 Answers

I've never seen a <= i if true

<= is one of the Ruby Comparison Operators:

Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.

i > a ? is_fibonacci?(i, a + b, a) : a <= i if true means - i > a ? is_fibonacci?(i, a + b, a) : a <= i the whole expression will be evaluated when your if condition results in true.

like image 196
Arup Rakshit Avatar answered Oct 23 '22 12:10

Arup Rakshit