class SchrodingersCat

Attributes

else[RW]
Note:           ##

These can’t be overriden as they are not methods but low-level operators… ):

define_method(:"&&") {|obj| false }; define_method(:"||") {|obj| obj }

which means I can’t reliably do something like record.assuming_a(User).authentications.first || raise “You didn’t supply a user with authentications!” because if sc.is_a?(SchrodingersCat), we ideally want: sc || false # => false true && sc # => false but instead, as || and && are low-level operators for short-circuiting, we get: sc || false # => sc true && sc # => sc However, though normally nil is the only object which should respond to nil? with a true, so does SchrodingersCat whose MODEL_OBJECT is nil.

method_chain[RW]
Note:           ##

These can’t be overriden as they are not methods but low-level operators… ):

define_method(:"&&") {|obj| false }; define_method(:"||") {|obj| obj }

which means I can’t reliably do something like record.assuming_a(User).authentications.first || raise “You didn’t supply a user with authentications!” because if sc.is_a?(SchrodingersCat), we ideally want: sc || false # => false true && sc # => false but instead, as || and && are low-level operators for short-circuiting, we get: sc || false # => sc true && sc # => sc However, though normally nil is the only object which should respond to nil? with a true, so does SchrodingersCat whose MODEL_OBJECT is nil.

original[RW]
Note:           ##

These can’t be overriden as they are not methods but low-level operators… ):

define_method(:"&&") {|obj| false }; define_method(:"||") {|obj| obj }

which means I can’t reliably do something like record.assuming_a(User).authentications.first || raise “You didn’t supply a user with authentications!” because if sc.is_a?(SchrodingersCat), we ideally want: sc || false # => false true && sc # => false but instead, as || and && are low-level operators for short-circuiting, we get: sc || false # => sc true && sc # => sc However, though normally nil is the only object which should respond to nil? with a true, so does SchrodingersCat whose MODEL_OBJECT is nil.

Public Class Methods

new(original, attrs={}) click to toggle source
# File lib/schrodingers_cat/schrodingers_cat.rb, line 29
def initialize(original, attrs={})
  self.original, self.method_chain  = original, Array.wrap(attrs[:method_chain])
  self.else, @_else_set             = attrs[:else], true if attrs.key?(:else)
end

Public Instance Methods

dup() click to toggle source

delegate *[ “==”, “eql?”, “&”, “^”, “|” ].map(&:intern), :to => :MODEL_OBJECT

# File lib/schrodingers_cat/schrodingers_cat.rb, line 48
def dup; nil; end

Private Instance Methods

method_missing(method_sym, *arguments, &block) click to toggle source
# File lib/schrodingers_cat/schrodingers_cat.rb, line 50
def method_missing(method_sym, *arguments, &block)
  return self.else if @_else_set
  self.method_chain << { method_sym => arguments.push(&block) }
  self
end