Skip to content

Instantly share code, notes, and snippets.

@beaucollins
Created October 26, 2010 17:04
Show Gist options
  • Save beaucollins/647301 to your computer and use it in GitHub Desktop.
Save beaucollins/647301 to your computer and use it in GitHub Desktop.
class Object
def if_present?(&blk)
return self unless present?
if blk.arity == -1
instance_eval(&blk)
else
blk.call(self)
end
self
end
end
str = "string".if_present? do |s|
s.reverse!
end
puts str
str = "string".if_present? do
reverse!
end
puts str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment