From 961945046848492ddc541700419cf553e7817c94 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 29 Aug 2014 15:19:32 -0700 Subject: Use instance_eval on @tenderlove's suggestion :trollface: --- activesupport/lib/active_support/core_ext/object/blank.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index 893858fcd6..99fd22ff56 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -40,15 +40,16 @@ class Object # region = params[:state].presence || params[:country].presence || 'US' # # You can also use this with a block that will be yielded if the object is present - # and the result of that block will then be returned + # and the result of that block will then be returned. The block itself is run against + # the instance you're running #presence on (using instance_eval) # - # project.account.owner.presence { |p| p.name.first } || 'Nobody' + # project.account.owner.presence { name.first } || 'Nobody' # # @return [Object] - def presence + def presence(&block) if present? if block_given? - yield self + instance_eval(&block) else self end -- cgit v1.2.3