4 ms·
I'd like to point out that while Ruby does support the puts("This was true.") if true syntax, that isn't how most people write if statements in Ruby, in m
by innocentoldguy 5y ago
I'd like to point out that while Ruby does support the
puts("This was true.") if true
syntax, that isn't how most people write if statements in Ruby, in my experience. Ruby also supports the common
if true
puts("This was true.")
end
format, which is how I typically see if statements formatted in Ruby code.
I wish the article had made that clear.
- mlinksva 5y agoThe article is clearly :) saying the former should not be supported at all. On your point, I'm not sure how influential rubocop is (I only use Ruby fairly casually, and try to take its suggestions) but for short conditionals, https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/IfUnlessModifier https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/IfUn...
- fouc 5y agodo_stuff(bar) if condition Foo.do_something unless qux.empty? This stuff is pretty common in ruby if it's short & clear.
- redbar0n 5y agoGood point. I agree. Most Ruby code uses `if <conditional> <expression> end`. Tried to rephrase it now so it gives the impression that `<expression> if <conditional>` is merely syntax that Ruby allows.
- fellellor 5y agoI think the convention is to only use the <expression><if…> for a guard statement. ie `return if condition true|false` which is perfectly readable. A lot of language angst seems based on specific syntax issues, for people migrating/visiting from other programming “cultures” rather than community evolved style issues.