aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/array/conversions.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/array/conversions.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/array/conversions.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb
index b516f58bff..35d010b164 100644
--- a/activesupport/lib/active_support/core_ext/array/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -26,6 +26,24 @@ module ActiveSupport #:nodoc:
join '/'
end
+ def self.included(klass) #:nodoc:
+ klass.send(:alias_method, :to_default_s, :to_s)
+ klass.send(:alias_method, :to_s, :to_formatted_s)
+ end
+
+ def to_formatted_s(format = :default)
+ case format
+ when :db
+ if respond_to?(:empty?) && self.empty?
+ "null"
+ else
+ collect { |element| element.id }.join(",")
+ end
+ else
+ to_default_s
+ end
+ end
+
def to_xml(options = {})
raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml }