Skip to content

Instantly share code, notes, and snippets.

@beaucollins
Forked from anonymous/snippet.rb
Created October 26, 2010 17:02
Show Gist options
  • Save beaucollins/647297 to your computer and use it in GitHub Desktop.
Save beaucollins/647297 to your computer and use it in GitHub Desktop.
class Object
def if_present?(&blk)
if blk.arity == -1
instance_eval(&blk)
else
blk.call(self)
end
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