Despite the lack of such functionality out of the box, you can do:
some_object.some_attribute.tap do |attr| attr.present? && call_smth(attr) end
On the other hand, Rails provides so many monkeypatches that one could add one to this circus:
class Object def presense_with_rails raise 'Block required' unless block_given? yield self if self.present? # requires rails end def presense_without_rails raise 'Block required' unless block_given? skip = case self when NilClass, FalseClass then true when String, Array then empty? else false end yield self unless skip end end
source share