I learned about postfix if in the reference book, so I wrote an article to understand it.
If and unless can be placed not only at the beginning of the line, but also after the phrase you want to evaluate when the condition is met. This way of writing is called "postfix if".
Click here for if https://qiita.com/muffin-men/items/fd8637bb1b98cb369c5b
Click here for unless https://qiita.com/muffin-men/items/9d3ab806634624f5f29f
#This will be output
puts 'Good morning' if true
#This is not output
puts 'Thank you for your support' if false
If you use a postfix if, you can only describe the processing for one line, and you cannot write else. If the process spans multiple lines or you want to write other conditions such as else, use a normal if. Postfix ifs are often used in simple cases where the process is only one line.
・ Ruby on rails 5 that can be used in the field
Recommended Posts