From: "shan (Shannon Skipper)" Date: 2021-11-16T00:49:48+00:00 Subject: [ruby-core:106074] [Ruby master Feature#18332] a ? b Issue #18332 has been updated by shan (Shannon Skipper). Control flow operators are another option that reverses the direction. ``` ruby true and 'font-bold' #=> "font-bold" 'font-bold' if true #=> "font-bold" nil and 'font-bold' #=> nil 'font-bold' if nil #=> nil ``` ---------------------------------------- Feature #18332: a ? b https://bugs.ruby-lang.org/issues/18332#change-94663 * Author: dorianmariefr (Dorian Mari��) * Status: Open * Priority: Normal ---------------------------------------- It would be a shortcut for `a ? b : nil`: e.g. ``` "#{current_path == "/" ? "font-bold"}" "#{user.admin? ? "text-red-600"}" ``` Doing `a && b` returns `false` which converted to a string gives `"false"`. When `nil` converts to a string it gives `""`. I would use it mostly in string interpolations. -- https://bugs.ruby-lang.org/ Unsubscribe: