Skip to content

Instantly share code, notes, and snippets.

View ajlai's full-sized avatar

Anthony Lai ajlai

  • San Francisco Bay Area, CA
View GitHub Profile
anonymous
anonymous / self_unless.rb
Created December 13, 2012 00:06
Making Ruby || / && chaining for non nil/false values nicer
class Object
# Usage:
# maybe_zero.self_unless(&:zero?) || zero_fallback
# # => either maybe_zero or zero_fallback (if maybe_zero was zero)
def self_unless
self unless yield(self)
end
end