Module: ActiveSupport::CoreExtensions::Range::Conversions

Included in:
Range
Defined in:
lib/active_support/core_ext/range/conversions.rb

Overview

Getting dates in different convenient string representations and other objects

Constant Summary collapse

DATE_FORMATS =
{
  :db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" }
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

:nodoc:


10
11
12
13
# File 'lib/active_support/core_ext/range/conversions.rb', line 10

def self.included(klass) #:nodoc:
  klass.send(:alias_method, :to_default_s, :to_s)
  klass.send(:alias_method, :to_s, :to_formatted_s)
end

Instance Method Details

#to_formatted_s(format = :default) ⇒ Object


15
16
17
# File 'lib/active_support/core_ext/range/conversions.rb', line 15

def to_formatted_s(format = :default)
  DATE_FORMATS[format] ? DATE_FORMATS[format].call(first, last) : to_default_s   
end