Question on my code


#1



https://www.codecademy.com/en/courses/ruby-beginner-en-nOho7/0/5?curriculum_id=5059f8619189a5000201fbcb


def alphabetize(arr, rev=false)
    if rev
        arr.sort.reverse!
else
    arr.sort!
end
end


array = [ 5 , 3 ,8 , 6 ]

puts " #{alphabetize(array,true)} "

Hi. 1) why is it on the second line, we use "if rev" instead of "if rev=true/false" ? How does ruby know if we want to evaluate our if rev = true or false?
2) On the last line why does puts " #{alphabetize(array,true)} " works ? Shouldnt it be puts " #{alphabetize(array, rev = true)} " (following the parameter format) ?

PS : I am totally new to programming


#2

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