aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-02-25 23:06:04 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-02-25 23:06:04 +0000
commit99307b959b1c16ab1dd0400a7398019fe9d5494b (patch)
tree94a082a3c7f91c8a98596a8bcf29f2c99d4baa70 /activesupport
parent1aea4704dca570e3ef7abe69349ae2f161c7244b (diff)
downloadrails-99307b959b1c16ab1dd0400a7398019fe9d5494b.tar.gz
rails-99307b959b1c16ab1dd0400a7398019fe9d5494b.tar.bz2
rails-99307b959b1c16ab1dd0400a7398019fe9d5494b.zip
Added calculations: Base.count, Base.average, Base.sum, Base.minimum, Base.maxmium, and the generic Base.calculate. All can be used with :group and :having. Calculations and statitics need no longer require custom SQL. #3958 [Rick Olson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3646 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/ordered_options.rb34
1 files changed, 23 insertions, 11 deletions
diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb
index ed5d4d3167..0e97578b3e 100644
--- a/activesupport/lib/active_support/ordered_options.rb
+++ b/activesupport/lib/active_support/ordered_options.rb
@@ -1,7 +1,5 @@
-class OrderedOptions < Array #:nodoc:
- def []=(key, value)
- key = key.to_sym
-
+class OrderedHash < Array #:nodoc:
+ def []=(key, value)
if pair = find_pair(key)
pair.pop
pair << value
@@ -11,16 +9,12 @@ class OrderedOptions < Array #:nodoc:
end
def [](key)
- pair = find_pair(key.to_sym)
+ pair = find_pair(key)
pair ? pair.last : nil
end
- def method_missing(name, *args)
- if name.to_s =~ /(.*)=$/
- self[$1.to_sym] = args.first
- else
- self[name]
- end
+ def keys
+ self.collect { |i| i.first }
end
private
@@ -28,4 +22,22 @@ class OrderedOptions < Array #:nodoc:
self.each { |i| return i if i.first == key }
return false
end
+end
+
+class OrderedOptions < OrderedHash #:nodoc:
+ def []=(key, value)
+ super(key.to_sym, value)
+ end
+
+ def [](key)
+ super(key.to_sym)
+ end
+
+ def method_missing(name, *args)
+ if name.to_s =~ /(.*)=$/
+ self[$1.to_sym] = args.first
+ else
+ self[name]
+ end
+ end
end \ No newline at end of file