Often I need to check if some value is empty and write that "No data":
@user.address.blank? ? "We don't know user address" : @user.address
And when we have about 20-30 fields that we need to process, it becomes ugly.
I created an extended String class using the or method
class String def or(what) self.strip.blank? ? what : self end end @user.address.or("We don't know user address")
Now he looks better. But he's still raw and rude
How it would be better to solve my problem. Perhaps it would be better to extend the ActiveSupport class or use a helper method or mixins or something else. What ruby โโideology, your experience and best practices can tell me.
ruby ruby-on-rails
fl00r Jan 27 2018-11-11T00: 00Z
source share