Skip to content

Instantly share code, notes, and snippets.

@iosadchiy
Created November 12, 2010 23:07
Show Gist options
  • Save iosadchiy/674864 to your computer and use it in GitHub Desktop.
Save iosadchiy/674864 to your computer and use it in GitHub Desktop.
def self.find(*args)
ret = nil
if args.first.is_a? Symbol
if args.first == :all
ret = Array.new
if args[1].is_a? Hash
Company.all.each do |a|
tests = Array.new
args[1][:conditions].each do |atr, cond|
if a.read_attribute(atr) != cond
tests << false
else
tests << true
end
end
unless tests.include? false
ret << a
end
end
end
elsif args.first == :first
if args[1].is_a? Hash
Company.all.each do |a|
tests = Array.new
args[1][:conditions].each do |atr, cond|
if a.read_attribute(atr) != cond
tests << false
else
tests << true
end
end
unless tests.include? false
ret = a
break a
end
end
end
else
super
return
end
return ret
else
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment