From 99307b959b1c16ab1dd0400a7398019fe9d5494b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 25 Feb 2006 23:06:04 +0000 Subject: 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 --- .../lib/active_support/ordered_options.rb | 34 +++++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'activesupport') 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 -- cgit v1.2.3