Why inv==true and not inv=true?


#1

Hello.

I had the following error at the beginning: (ruby):2: warning: found = in conditional, should be ==
So I modified it and it's now working well but I don't get it ... why the boolean is defined with only one = in my method here: def alphabetique(tableau, inv=false)

And later I've to tell Ruby that if this same boolean is == true, the array has to be reversed ?
Why in this case should we use a double == ?

Thanks!

def alphabetique(tableau, inv=false)
    tableau.sort!
    if inv==true
        tableau.reverse!
else
    return tableau
end
end

nombres = [12,55,200,1]

alphabetique(nombres)
puts nombres

`


#2

= means assign value
== means check if values are equal


#3

Ok thanks but could you explain to me what Ruby understand when I write if inv=true ?


#4

then it will simply assign true to inv, so you now overwritten whatever was stored in inv, so now this condition is always true


#5

Alright I better not do that then :smile:
I get it now, many thanks @stetim94 for your help !


#6

best not :smiley:


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.