Try To Use “Ternary” Operator

by

in

Many developers will use the “if-else” statement for single line functions, For example,def role(admin) if admin == “admin” return true else return false end end

Why we don’t start using a ternary here?def role(admin)

 admin == "admin" ? true : false end
Another way to use the conditions as the return object.def role(admin) admin == "admin" end

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *