Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ci skip] Update documentation for Range#to_formatted_s #19128

Merged
merged 1 commit into from Feb 28, 2015

Conversation

@davydovanton
Copy link
Contributor

davydovanton commented Feb 28, 2015

Added information about default :db format and added information about custom formats 馃帀

@kaspth

This comment has been minimized.

Copy link
Member

kaspth commented Feb 28, 2015

I don't think we should tell people to replace and break the RANGE_FORMATS, but extend it. Instead your example could be Range::RANGE_FORMATS[:example] = ->(start, stop) { ... }.

@davydovanton

This comment has been minimized.

Copy link
Contributor Author

davydovanton commented Feb 28, 2015

@kaspth yes, you're right, thanks! 鉂わ笍

@davydovanton davydovanton force-pushed the davydovanton:update-doc-range-to-s branch Feb 28, 2015
@davydovanton

This comment has been minimized.

Copy link
Contributor Author

davydovanton commented Feb 28, 2015

@kaspth fixed this

@davydovanton davydovanton force-pushed the davydovanton:update-doc-range-to-s branch 2 times, most recently Feb 28, 2015
@kaspth

This comment has been minimized.

Copy link
Member

kaspth commented Feb 28, 2015

I'd love it if we could make the documentation here more consistent with Date's to_formatted_s:

# Convert to a formatted string. See DATE_FORMATS for predefined formats.
#
# This method is aliased to <tt>to_s</tt>.
#
# date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
#
# date.to_formatted_s(:db) # => "2007-11-10"
# date.to_s(:db) # => "2007-11-10"
#
# date.to_formatted_s(:short) # => "10 Nov"
# date.to_formatted_s(:long) # => "November 10, 2007"
# date.to_formatted_s(:long_ordinal) # => "November 10th, 2007"
# date.to_formatted_s(:rfc822) # => "10 Nov 2007"
# date.to_formatted_s(:iso8601) # => "2007-11-10"
#
# == Adding your own date formats to to_formatted_s
# You can add your own formats to the Date::DATE_FORMATS hash.
# Use the format name as the hash key and either a strftime string
# or Proc instance that takes a date argument as the value.
#
# # config/initializers/date_formats.rb
# Date::DATE_FORMATS[:month_and_year] = '%B %Y'
# Date::DATE_FORMATS[:short_ordinal] = ->(date) { date.strftime("%B #{date.day.ordinalize}") }
def to_formatted_s(format = :default)
鉂わ笍

@davydovanton davydovanton force-pushed the davydovanton:update-doc-range-to-s branch Feb 28, 2015
@davydovanton

This comment has been minimized.

Copy link
Contributor Author

davydovanton commented Feb 28, 2015

@kaspth fixed this too 馃槂

@davydovanton davydovanton force-pushed the davydovanton:update-doc-range-to-s branch Feb 28, 2015
@kaspth
kaspth reviewed Feb 28, 2015
View changes
activesupport/lib/active_support/core_ext/range/conversions.rb Outdated
# == Adding your own range formats to to_formatted_s
# You can add your own formats to the Range::RANGE_FORMATS hash.
# Use the format name as the hash key and either a Proc instance
# that takes a start and stop arguments as the value.

This comment has been minimized.

Copy link
@kaspth

kaspth Feb 28, 2015

Member

Remove a: that takes a start and stop arguments as the value.

@kaspth
kaspth reviewed Feb 28, 2015
View changes
activesupport/lib/active_support/core_ext/range/conversions.rb Outdated
#
# == Adding your own range formats to to_formatted_s
# You can add your own formats to the Range::RANGE_FORMATS hash.
# Use the format name as the hash key and either a Proc instance

This comment has been minimized.

Copy link
@kaspth

kaspth Feb 28, 2015

Member

鉁傦笍 either

@kaspth
kaspth reviewed Feb 28, 2015
View changes
activesupport/lib/active_support/core_ext/range/conversions.rb Outdated
# that takes a start and stop arguments as the value.
#
# # config/initializers/range_formats.rb
# Range::RANGE_FORMATS[:example] = ->(start, stop) { "you range between '#{start.to_s(:db)}' and '#{stop.to_s(:db)}'" }

This comment has been minimized.

Copy link
@kaspth

kaspth Feb 28, 2015

Member

Let's use a more real example, like:

Range::RANGE_FORMATS[:short] = ->(start, stop) { "Between #{start.to_s(:short)} and #{stop.to_s(:short)}" }
@davydovanton davydovanton force-pushed the davydovanton:update-doc-range-to-s branch to 032d279 Feb 28, 2015
@davydovanton

This comment has been minimized.

Copy link
Contributor Author

davydovanton commented Feb 28, 2015

@kaspth fixed all. Thanks for review! 馃挌 馃挍 鉂わ笍

@kaspth

This comment has been minimized.

Copy link
Member

kaspth commented Feb 28, 2015

No problem, 馃憤. The documentation here is way better because of your work 鉂わ笍

kaspth added a commit that referenced this pull request Feb 28, 2015
[ci skip] Update documentation for Range#to_formatted_s
@kaspth kaspth merged commit 1db5ecf into rails:master Feb 28, 2015
@kaspth

This comment has been minimized.

Copy link
Member

kaspth commented Feb 28, 2015

Holy crap! You got the 50000th commit to Rails 馃槈

@davydovanton davydovanton deleted the davydovanton:update-doc-range-to-s branch Feb 28, 2015
@davydovanton

This comment has been minimized.

Copy link
Contributor Author

davydovanton commented Feb 28, 2015

WOW! 馃帀 thanks! 馃専

@vipulnsward

This comment has been minimized.

Copy link
Member

vipulnsward commented Feb 28, 2015

馃帀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can鈥檛 perform that action at this time.