Froze rails gems
[depot.git] / vendor / rails / activesupport / lib / active_support / core_ext / range / conversions.rb
1 module ActiveSupport #:nodoc:
2 module CoreExtensions #:nodoc:
3 module Range #:nodoc:
4 # Getting ranges in different convenient string representations and other objects
5 module Conversions
6 RANGE_FORMATS = {
7 :db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" }
8 }
9
10 def self.included(base) #:nodoc:
11 base.class_eval do
12 alias_method :to_default_s, :to_s
13 alias_method :to_s, :to_formatted_s
14 end
15 end
16 # Gives a human readable format of the range.
17 #
18 # ==== Example:
19 #
20 # [1..100].to_formatted_s # => "1..100"
21 def to_formatted_s(format = :default)
22 RANGE_FORMATS[format] ? RANGE_FORMATS[format].call(first, last) : to_default_s
23 end
24 end
25 end
26 end
27 end