Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/schrodingers_cat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def initialize(original, attrs={})
class_eval %{ def #{meth}; MODEL_OBJECT.#{meth}; end; }
end
#delegate *[ 'inspect', 'to_s', 'to_i', 'nil?', 'empty?' ,'blank?' ].map(&:intern), :to => :MODEL_OBJECT

if Rails.env.development?
def inspect; "nil (SchrodingersCat)"; end
end
Expand All @@ -47,7 +47,7 @@ def inspect; "nil (SchrodingersCat)"; end
class_eval %{ def #{meth}(other); MODEL_OBJECT.#{meth}(other); end; }
end
#delegate *[ "==", "eql?", "&", "^", "|" ].map(&:intern), :to => :MODEL_OBJECT

def dup; nil; end

def method_missing(method_sym, *arguments, &block)
Expand Down
12 changes: 6 additions & 6 deletions lib/schrodingers_cat/core_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def only_unless_a?(*others, &block)
def assuming_a(*others, &block)
if_a?(*others.merge_options(:chain => true), &block)
end

##################################
# Exact comparison of #== in is_one_of? rather than utilizing #=== in #is_one_kind_of
###############################
Expand All @@ -61,26 +61,26 @@ def unless_equals_a?(*others, &block); if_equals_a?(*others.merge_optio
def only_if_equals_a?(*others, &block); if_equals_a?(*others.merge_options(:else => nil), &block); end
def only_unless_equals_a?(*others, &block); unless_equals_a?(*others.merge_options(:else => nil), &block); end
def assuming_equals_a(*others, &block); if_equals_a?(*others.merge_options(:chain => true), &block); end

#########################
# Custom conditionals. ##
#########################
def if?(varied, *args, &block) if_a?(*args.merge_options(:conditions => resolve_conditions(varied)), &block); end
def unless?(*args, &block); if?(*args.merge_options(:opposite => true), &block); end
def only_if?(*args, &block); if?(*args.merge_options(:else => nil), &block); end
def only_unless?(*args, &block); only_if?(*args.merge_options(:opposite => true), &block); end
#def assuming(*args, &block); if?(*args.merge_options(:chain => true), &block); end
#def assuming(*args, &block); if?(*args.merge_options(:chain => true), &block); end

#########################
# Utilities ##
#########################
def present_else_nil; present_else(nil); end
def significant_else_nil; significant_else(nil); end

protected
def present_else(other); if?(:present?, :else => other) { self }; end
def significant_else(other); if?(:significant?, :else => other) { self }; end

private
def resolve_conditions(varied)
varied.is_a?(Symbol) ? __send__(varied) : varied.is_a?(Array) ? __send__(*varied) : varied.is_a?(String) ? varied[0] =~ /\./ ? __send__(:eval, "self#{varied}") : eval(varied) : !!varied
Expand Down
8 changes: 4 additions & 4 deletions lib/schrodingers_cat/dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ class Array
def options_extractable?
last.is_a?(Hash) && last.extractable_options?
end

def flatten_splat(with_bang=false)
flatten_splat_needed? ? with_bang ? flatten! : flatten : self
end

def flatten_splat!
flatten_splat(true)
end

def flatten_splat_needed?
self.size == 1 and first.is_a?(Array)
end
private :flatten_splat_needed?

def merge_options(update_hash={})
endex, base_hash = options_extractable? ? [ -2, last ] : [ -1, {} ]
Array[ *self[0..endex], base_hash.merge(update_hash || {}) ]
Expand All @@ -24,5 +24,5 @@ def merge_options(update_hash={})
def merge_options!(update_hash={})
push(extract_options!(update_hash))
end; alias_method :merge_opts!, :merge_options!

end