Hey guys,
I find myself doing stuff like this a lot:
self.email.blank? ? self.name : self.email
Anyone feel like adding an 'or' method to nil and String (a la blank?) so
that this will work:
self.email.or(self.name)
It would be as simple as adding this file to ActiveSupport
activesupport/lib/core_ext/or.rb
class String
def or(val)
self == "" ? val : self
end
end
class NilClass
def or(val)
val
end
end
I'll submit a patch of this + tests to LH if people are interested.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---