Skip to content

Instantly share code, notes, and snippets.

@suginoy
Created February 16, 2018 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suginoy/105d2e32a9c3d69765a737b9383cb666 to your computer and use it in GitHub Desktop.
Save suginoy/105d2e32a9c3d69765a737b9383cb666 to your computer and use it in GitHub Desktop.
my extension of Object class
require 'active_support'
require 'active_support/core_ext'
class Object
# # my Object#survive = ActiveSupport's Object#presence + block
def survive
if present?
if block_given?
self if yield(self)
else
self
end
end
end
end
# example
1.survive(&:even?) # => nil
2.survive(&:even?) # => 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment