Module: ActiveSupport::CoreExtensions::Range::Conversions
- Included in:
- Range
- Defined in:
- lib/gems/activesupport-2.2.2/lib/active_support/core_ext/range/conversions.rb
Overview
Getting ranges in different convenient string representations and other objects
Constant Summary collapse
- RANGE_FORMATS =
{ :db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" } }
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#to_formatted_s(format = :default) ⇒ Object
Gives a human readable format of the range.
Class Method Details
.included(base) ⇒ Object
:nodoc:
10 11 12 13 14 15 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/range/conversions.rb', line 10 def self.included(base) #:nodoc: base.class_eval do alias_method :to_default_s, :to_s alias_method :to_s, :to_formatted_s end end |
Instance Method Details
#to_formatted_s(format = :default) ⇒ Object
Gives a human readable format of the range.
Example:
[1..100].to_formatted_s # => "1..100"
21 22 23 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/range/conversions.rb', line 21 def to_formatted_s(format = :default) RANGE_FORMATS[format] ? RANGE_FORMATS[format].call(first, last) : to_default_s end |