Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8699

Show
Ignore:
Timestamp:
01/23/08 02:53:29 (8 months ago)
Author:
gbuesing
Message:

Refactor Time and DateTime #to_formatted_s: use ternary instead of nested if/else

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r8698 r8699  
    11*SVN* 
     2 
     3* Refactor Time and DateTime #to_formatted_s: use ternary instead of nested if/else [Geoff Buesing] 
    24 
    35* Adding Time and DateTime #formatted_offset, for outputting +HH:MM utc offset strings with cross-platform consistency [Geoff Buesing] 
  • trunk/activesupport/lib/active_support/core_ext/date_time/conversions.rb

    r8698 r8699  
    4242        #   Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") } 
    4343        def to_formatted_s(format = :default) 
    44           if formatter = ::Time::DATE_FORMATS[format] 
    45             if formatter.respond_to?(:call) 
    46               formatter.call(self).to_s 
    47             else 
    48               strftime(formatter) 
    49             end 
    50           else 
    51             to_datetime_default_s 
    52           end 
     44          return to_default_s unless formatter = ::Time::DATE_FORMATS[format] 
     45          formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter) 
    5346        end 
    5447 
  • trunk/activesupport/lib/active_support/core_ext/time/conversions.rb

    r8698 r8699  
    4646        #   Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") } 
    4747        def to_formatted_s(format = :default) 
    48           if formatter = DATE_FORMATS[format] 
    49             if formatter.respond_to?(:call) 
    50               formatter.call(self).to_s 
    51             else 
    52               strftime(formatter) 
    53             end 
    54           else 
    55             to_default_s 
    56           end 
     48          return to_default_s unless formatter = DATE_FORMATS[format] 
     49          formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter) 
    5750        end 
    5851