Skip to content

Instantly share code, notes, and snippets.

@hyoshida
hyoshida / maybe.rb
Last active August 29, 2015 14:04 — forked from kkismd/maybe.rb
class Maybe < BasicObject
UNPROXIED_METHODS = %i(__send__ __id__ send object_id extend instance_eval initialize block_given? raise caller method)
delegate *(::NilClass.instance_methods - UNPROXIED_METHODS), to: :@just
def initialize(obj)
@just = obj
end
# for debug
def associations_for_includes(recursive: true, except: nil, _breadcrumb: [])
_breadcrumb << self.class_name
self.reflect_on_all_associations.map do |association_reflection|
association_name = association_reflection.name
class_name = association_reflection.class_name
next if _breadcrumb.include?(class_name)
next if association_reflection.options.has_key?(:polymorphic)
case except