Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update some AS code examples to 1.9 hash syntax [ci skip]

  • Loading branch information...
commit f4e180578c673194f58d4ff5a4a656cc51b2249e 1 parent 961355a
@frodsan frodsan authored
View
19 activesupport/lib/active_support/core_ext/module/delegation.rb
@@ -18,7 +18,7 @@ class Module
#
# class Foo < ActiveRecord::Base
# belongs_to :greeter
- # delegate :hello, :to => :greeter
+ # delegate :hello, to: :greeter
# end
#
# Foo.new.hello # => "hello"
@@ -28,7 +28,7 @@ class Module
#
# class Foo < ActiveRecord::Base
# belongs_to :greeter
- # delegate :hello, :goodbye, :to => :greeter
+ # delegate :hello, :goodbye, to: :greeter
# end
#
# Foo.new.goodbye # => "goodbye"
@@ -43,9 +43,9 @@ class Module
# def initialize
# @instance_array = [8,9,10,11]
# end
- # delegate :sum, :to => :CONSTANT_ARRAY
- # delegate :min, :to => :@@class_array
- # delegate :max, :to => :@instance_array
+ # delegate :sum, to: :CONSTANT_ARRAY
+ # delegate :min, to: :@@class_array
+ # delegate :max, to: :@instance_array
# end
#
# Foo.new.sum # => 6
@@ -59,7 +59,7 @@ class Module
# Person = Struct.new(:name, :address)
#
# class Invoice < Struct.new(:client)
- # delegate :name, :address, :to => :client, :prefix => true
+ # delegate :name, :address, to: :client, prefix: true
# end
#
# john_doe = Person.new('John Doe', 'Vimmersvej 13')
@@ -70,7 +70,7 @@ class Module
# It is also possible to supply a custom prefix.
#
# class Invoice < Struct.new(:client)
- # delegate :name, :address, :to => :client, :prefix => :customer
+ # delegate :name, :address, to: :client, prefix: :customer
# end
#
# invoice = Invoice.new(john_doe)
@@ -86,7 +86,7 @@ class Module
# def initialize(bar = nil)
# @bar = bar
# end
- # delegate :zoo, :to => :bar
+ # delegate :zoo, to: :bar
# end
#
# Foo.new.zoo # raises NoMethodError exception (you called nil.zoo)
@@ -96,11 +96,10 @@ class Module
# def initialize(bar = nil)
# @bar = bar
# end
- # delegate :zoo, :to => :bar, :allow_nil => true
+ # delegate :zoo, to: :bar, allow_nil: true
# end
#
# Foo.new.zoo # returns nil
- #
def delegate(*methods)
options = methods.pop
unless options.is_a?(Hash) && to = options[:to]
View
4 activesupport/lib/active_support/core_ext/module/deprecation.rb
@@ -3,8 +3,8 @@
class Module
# Declare that a method has been deprecated.
# deprecate :foo
- # deprecate :bar => 'message'
- # deprecate :foo, :bar, :baz => 'warning!', :qux => 'gone!'
+ # deprecate bar: 'message'
+ # deprecate :foo, :bar, baz: 'warning!', qux: 'gone!'
def deprecate(*method_names)
ActiveSupport::Deprecation.deprecate_methods(self, *method_names)
end
View
128 activesupport/lib/active_support/core_ext/numeric/conversions.rb
@@ -14,89 +14,89 @@ class Numeric
# ==== Examples
#
# Phone Numbers:
- # 5551234.to_s(:phone) # => 555-1234
- # 1235551234.to_s(:phone) # => 123-555-1234
- # 1235551234.to_s(:phone, :area_code => true) # => (123) 555-1234
- # 1235551234.to_s(:phone, :delimiter => " ") # => 123 555 1234
- # 1235551234.to_s(:phone, :area_code => true, :extension => 555) # => (123) 555-1234 x 555
- # 1235551234.to_s(:phone, :country_code => 1) # => +1-123-555-1234
- # 1235551234.to_s(:phone, :country_code => 1, :extension => 1343, :delimiter => ".")
+ # 5551234.to_s(:phone) # => 555-1234
+ # 1235551234.to_s(:phone) # => 123-555-1234
+ # 1235551234.to_s(:phone, area_code: true) # => (123) 555-1234
+ # 1235551234.to_s(:phone, delimiter: ' ') # => 123 555 1234
+ # 1235551234.to_s(:phone, area_code: true, extension: 555) # => (123) 555-1234 x 555
+ # 1235551234.to_s(:phone, country_code: 1) # => +1-123-555-1234
+ # 1235551234.to_s(:phone, country_code: 1, extension: 1343, delimiter: '.')
# # => +1.123.555.1234 x 1343
#
# Currency:
- # 1234567890.50.to_s(:currency) # => $1,234,567,890.50
- # 1234567890.506.to_s(:currency) # => $1,234,567,890.51
- # 1234567890.506.to_s(:currency, :precision => 3) # => $1,234,567,890.506
- # 1234567890.506.to_s(:currency, :locale => :fr) # => 1 234 567 890,51 €
- # -1234567890.50.to_s(:currency, :negative_format => "(%u%n)")
+ # 1234567890.50.to_s(:currency) # => $1,234,567,890.50
+ # 1234567890.506.to_s(:currency) # => $1,234,567,890.51
+ # 1234567890.506.to_s(:currency, precision: 3) # => $1,234,567,890.506
+ # 1234567890.506.to_s(:currency, locale: :fr) # => 1 234 567 890,51 €
+ # -1234567890.50.to_s(:currency, negative_format: '(%u%n)')
# # => ($1,234,567,890.50)
- # 1234567890.50.to_s(:currency, :unit => "&pound;", :separator => ",", :delimiter => "")
+ # 1234567890.50.to_s(:currency, unit: '&pound;', separator: ',', delimiter: '')
# # => &pound;1234567890,50
- # 1234567890.50.to_s(:currency, :unit => "&pound;", :separator => ",", :delimiter => "", :format => "%n %u")
+ # 1234567890.50.to_s(:currency, unit: '&pound;', separator: ',', delimiter: '', format: '%n %u')
# # => 1234567890,50 &pound;
#
# Percentage:
- # 100.to_s(:percentage) # => 100.000%
- # 100.to_s(:percentage, :precision => 0) # => 100%
- # 1000.to_s(:percentage, :delimiter => '.', :separator => ',') # => 1.000,000%
- # 302.24398923423.to_s(:percentage, :precision => 5) # => 302.24399%
- # 1000.to_s(:percentage, :locale => :fr) # => 1 000,000%
- # 100.to_s(:percentage, :format => "%n %") # => 100 %
+ # 100.to_s(:percentage) # => 100.000%
+ # 100.to_s(:percentage, precision: 0) # => 100%
+ # 1000.to_s(:percentage, delimiter: '.', separator: ',') # => 1.000,000%
+ # 302.24398923423.to_s(:percentage, precision: 5) # => 302.24399%
+ # 1000.to_s(:percentage, locale: :fr) # => 1 000,000%
+ # 100.to_s(:percentage, format: '%n %') # => 100 %
#
# Delimited:
- # 12345678.to_s(:delimited) # => 12,345,678
- # 12345678.05.to_s(:delimited) # => 12,345,678.05
- # 12345678.to_s(:delimited, :delimiter => ".") # => 12.345.678
- # 12345678.to_s(:delimited, :delimiter => ",") # => 12,345,678
- # 12345678.05.to_s(:delimited, :separator => " ") # => 12,345,678 05
- # 12345678.05.to_s(:delimited, :locale => :fr) # => 12 345 678,05
- # 98765432.98.to_s(:delimited, :delimiter => " ", :separator => ",")
+ # 12345678.to_s(:delimited) # => 12,345,678
+ # 12345678.05.to_s(:delimited) # => 12,345,678.05
+ # 12345678.to_s(:delimited, delimiter: '.') # => 12.345.678
+ # 12345678.to_s(:delimited, delimiter: ',') # => 12,345,678
+ # 12345678.05.to_s(:delimited, separator: ' ') # => 12,345,678 05
+ # 12345678.05.to_s(:delimited, locale: :fr) # => 12 345 678,05
+ # 98765432.98.to_s(:delimited, delimiter: ' ', separator: ',')
# # => 98 765 432,98
#
# Rounded:
- # 111.2345.to_s(:rounded) # => 111.235
- # 111.2345.to_s(:rounded, :precision => 2) # => 111.23
- # 13.to_s(:rounded, :precision => 5) # => 13.00000
- # 389.32314.to_s(:rounded, :precision => 0) # => 389
- # 111.2345.to_s(:rounded, :significant => true) # => 111
- # 111.2345.to_s(:rounded, :precision => 1, :significant => true) # => 100
- # 13.to_s(:rounded, :precision => 5, :significant => true) # => 13.000
- # 111.234.to_s(:rounded, :locale => :fr) # => 111,234
- # 13.to_s(:rounded, :precision => 5, :significant => true, :strip_insignificant_zeros => true)
+ # 111.2345.to_s(:rounded) # => 111.235
+ # 111.2345.to_s(:rounded, precision: 2) # => 111.23
+ # 13.to_s(:rounded, precision: 5) # => 13.00000
+ # 389.32314.to_s(:rounded, precision: 0) # => 389
+ # 111.2345.to_s(:rounded, significant: true) # => 111
+ # 111.2345.to_s(:rounded, precision: 1, significant: true) # => 100
+ # 13.to_s(:rounded, precision: 5, significant: true) # => 13.000
+ # 111.234.to_s(:rounded, locale: :fr) # => 111,234
+ # 13.to_s(:rounded, precision: 5, significant: true, strip_insignificant_zeros: true)
# # => 13
- # 389.32314.to_s(:rounded, :precision => 4, :significant => true) # => 389.3
- # 1111.2345.to_s(:rounded, :precision => 2, :separator => ',', :delimiter => '.')
+ # 389.32314.to_s(:rounded, precision: 4, significant: true) # => 389.3
+ # 1111.2345.to_s(:rounded, precision: 2, separator: ',', delimiter: '.')
# # => 1.111,23
#
# Human-friendly size in Bytes:
- # 123.to_s(:human_size) # => 123 Bytes
- # 1234.to_s(:human_size) # => 1.21 KB
- # 12345.to_s(:human_size) # => 12.1 KB
- # 1234567.to_s(:human_size) # => 1.18 MB
- # 1234567890.to_s(:human_size) # => 1.15 GB
- # 1234567890123.to_s(:human_size) # => 1.12 TB
- # 1234567.to_s(:human_size, :precision => 2) # => 1.2 MB
- # 483989.to_s(:human_size, :precision => 2) # => 470 KB
- # 1234567.to_s(:human_size, :precision => 2, :separator => ',') # => 1,2 MB
- # 1234567890123.to_s(:human_size, :precision => 5) # => "1.1229 TB"
- # 524288000.to_s(:human_size, :precision => 5) # => "500 MB"
+ # 123.to_s(:human_size) # => 123 Bytes
+ # 1234.to_s(:human_size) # => 1.21 KB
+ # 12345.to_s(:human_size) # => 12.1 KB
+ # 1234567.to_s(:human_size) # => 1.18 MB
+ # 1234567890.to_s(:human_size) # => 1.15 GB
+ # 1234567890123.to_s(:human_size) # => 1.12 TB
+ # 1234567.to_s(:human_size, precision: 2) # => 1.2 MB
+ # 483989.to_s(:human_size, precision: 2) # => 470 KB
+ # 1234567.to_s(:human_size, precision: 2, separator: ',') # => 1,2 MB
+ # 1234567890123.to_s(:human_size, precision: 5) # => "1.1229 TB"
+ # 524288000.to_s(:human_size, precision: 5) # => "500 MB"
#
# Human-friendly format:
- # 123.to_s(:human) # => "123"
- # 1234.to_s(:human) # => "1.23 Thousand"
- # 12345.to_s(:human) # => "12.3 Thousand"
- # 1234567.to_s(:human) # => "1.23 Million"
- # 1234567890.to_s(:human) # => "1.23 Billion"
- # 1234567890123.to_s(:human) # => "1.23 Trillion"
- # 1234567890123456.to_s(:human) # => "1.23 Quadrillion"
- # 1234567890123456789.to_s(:human) # => "1230 Quadrillion"
- # 489939.to_s(:human, :precision => 2) # => "490 Thousand"
- # 489939.to_s(:human, :precision => 4) # => "489.9 Thousand"
- # 1234567.to_s(:human, :precision => 4,
- # :significant => false) # => "1.2346 Million"
- # 1234567.to_s(:human, :precision => 1,
- # :separator => ',',
- # :significant => false) # => "1,2 Million"
+ # 123.to_s(:human) # => "123"
+ # 1234.to_s(:human) # => "1.23 Thousand"
+ # 12345.to_s(:human) # => "12.3 Thousand"
+ # 1234567.to_s(:human) # => "1.23 Million"
+ # 1234567890.to_s(:human) # => "1.23 Billion"
+ # 1234567890123.to_s(:human) # => "1.23 Trillion"
+ # 1234567890123456.to_s(:human) # => "1.23 Quadrillion"
+ # 1234567890123456789.to_s(:human) # => "1230 Quadrillion"
+ # 489939.to_s(:human, precision: 2) # => "490 Thousand"
+ # 489939.to_s(:human, precision: 4) # => "489.9 Thousand"
+ # 1234567.to_s(:human, precision: 4,
+ # significant: false) # => "1.2346 Million"
+ # 1234567.to_s(:human, precision: 1,
+ # separator: ',',
+ # significant: false) # => "1,2 Million"
def to_formatted_s(format = :default, options = {})
case format
when :phone
View
6 activesupport/lib/active_support/core_ext/numeric/time.rb
@@ -8,13 +8,13 @@ class Numeric
# These methods use Time#advance for precise date calculations when using from_now, ago, etc.
# as well as adding or subtracting their results from a Time object. For example:
#
- # # equivalent to Time.current.advance(:months => 1)
+ # # equivalent to Time.current.advance(months: 1)
# 1.month.from_now
#
- # # equivalent to Time.current.advance(:years => 2)
+ # # equivalent to Time.current.advance(years: 2)
# 2.years.from_now
#
- # # equivalent to Time.current.advance(:months => 4, :years => 5)
+ # # equivalent to Time.current.advance(months: 4, years: 5)
# (4.months + 5.years).from_now
#
# While these methods provide precise calculation when used as in the examples above, care
View
9 activesupport/lib/active_support/core_ext/object/blank.rb
@@ -43,7 +43,6 @@ class NilClass
# +nil+ is blank:
#
# nil.blank? # => true
- #
def blank?
true
end
@@ -53,7 +52,6 @@ class FalseClass
# +false+ is blank:
#
# false.blank? # => true
- #
def blank?
true
end
@@ -63,7 +61,6 @@ class TrueClass
# +true+ is not blank:
#
# true.blank? # => false
- #
def blank?
false
end
@@ -74,7 +71,6 @@ class Array
#
# [].blank? # => true
# [1,2,3].blank? # => false
- #
alias_method :blank?, :empty?
end
@@ -82,8 +78,7 @@ class Hash
# A hash is blank if it's empty:
#
# {}.blank? # => true
- # {:key => 'value'}.blank? # => false
- #
+ # { key: 'value' }.blank? # => false
alias_method :blank?, :empty?
end
@@ -94,7 +89,6 @@ class String
# ' '.blank? # => true
# ' '.blank? # => true
# ' something here '.blank? # => false
- #
def blank?
self !~ /[^[:space:]]/
end
@@ -105,7 +99,6 @@ class Numeric #:nodoc:
#
# 1.blank? # => false
# 0.blank? # => false
- #
def blank?
false
end
View
5 activesupport/lib/active_support/core_ext/object/duplicable.rb
@@ -31,7 +31,6 @@ class NilClass
#
# nil.duplicable? # => false
# nil.dup # => TypeError: can't dup NilClass
- #
def duplicable?
false
end
@@ -42,7 +41,6 @@ class FalseClass
#
# false.duplicable? # => false
# false.dup # => TypeError: can't dup FalseClass
- #
def duplicable?
false
end
@@ -53,7 +51,6 @@ class TrueClass
#
# true.duplicable? # => false
# true.dup # => TypeError: can't dup TrueClass
- #
def duplicable?
false
end
@@ -64,7 +61,6 @@ class Symbol
#
# :my_symbol.duplicable? # => false
# :my_symbol.dup # => TypeError: can't dup Symbol
- #
def duplicable?
false
end
@@ -75,7 +71,6 @@ class Numeric
#
# 3.duplicable? # => false
# 3.dup # => TypeError: can't dup Fixnum
- #
def duplicable?
false
end
View
15 activesupport/lib/active_support/core_ext/object/with_options.rb
@@ -10,16 +10,16 @@ class Object
# Without <tt>with_options></tt>, this code contains duplication:
#
# class Account < ActiveRecord::Base
- # has_many :customers, :dependent => :destroy
- # has_many :products, :dependent => :destroy
- # has_many :invoices, :dependent => :destroy
- # has_many :expenses, :dependent => :destroy
+ # has_many :customers, dependent: :destroy
+ # has_many :products, dependent: :destroy
+ # has_many :invoices, dependent: :destroy
+ # has_many :expenses, dependent: :destroy
# end
#
# Using <tt>with_options</tt>, we can remove the duplication:
#
# class Account < ActiveRecord::Base
- # with_options :dependent => :destroy do |assoc|
+ # with_options dependent: :destroy do |assoc|
# assoc.has_many :customers
# assoc.has_many :products
# assoc.has_many :invoices
@@ -29,14 +29,13 @@ class Object
#
# It can also be used with an explicit receiver:
#
- # I18n.with_options :locale => user.locale, :scope => 'newsletter' do |i18n|
+ # I18n.with_options locale: user.locale, scope: 'newsletter' do |i18n|
# subject i18n.t :subject
- # body i18n.t :body, :user_name => user.name
+ # body i18n.t :body, user_name: user.name
# end
#
# <tt>with_options</tt> can also be nested since the call is forwarded to its receiver.
# Each nesting level will merge inherited defaults in addition to their own.
- #
def with_options(options)
yield ActiveSupport::OptionMerger.new(self, options)
end
View
17 activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -62,14 +62,17 @@ def seconds_since_midnight
to_i - change(:hour => 0).to_i + (usec / 1.0e+6)
end
- # Returns a new Time where one or more of the elements have been changed according to the +options+ parameter. The time options
- # (<tt>:hour</tt>, <tt>:min</tt>, <tt>:sec</tt>, <tt>:usec</tt>) reset cascadingly, so if only the hour is passed, then minute, sec, and usec is set to 0.
- # If the hour and minute is passed, then sec and usec is set to 0. The +options+ parameter takes a hash with any of these keys: <tt>:year</tt>,
- # <tt>:month</tt>, <tt>:day</tt>, <tt>:hour</tt>, <tt>:min</tt>, <tt>:sec</tt>, <tt>:usec</tt>.
+ # Returns a new Time where one or more of the elements have been changed according
+ # to the +options+ parameter. The time options (<tt>:hour</tt>, <tt>:min</tt>,
+ # <tt>:sec</tt>, <tt>:usec</tt>) reset cascadingly, so if only the hour is passed,
+ # then minute, sec, and usec is set to 0. If the hour and minute is passed, then
+ # sec and usec is set to 0. The +options+ parameter takes a hash with any of these
+ # keys: <tt>:year</tt>, <tt>:month</tt>, <tt>:day</tt>, <tt>:hour</tt>, <tt>:min</tt>,
+ # <tt>:sec</tt>, <tt>:usec</tt>.
#
- # Time.new(2012, 8, 29, 22, 35, 0).change(:day => 1) # => Time.new(2012, 8, 1, 22, 35, 0)
- # Time.new(2012, 8, 29, 22, 35, 0).change(:year => 1981, :day => 1) # => Time.new(1981, 8, 1, 22, 35, 0)
- # Time.new(2012, 8, 29, 22, 35, 0).change(:year => 1981, :hour => 0) # => Time.new(1981, 8, 29, 0, 0, 0)
+ # Time.new(2012, 8, 29, 22, 35, 0).change(day: 1) # => Time.new(2012, 8, 1, 22, 35, 0)
+ # Time.new(2012, 8, 29, 22, 35, 0).change(year: 1981, day: 1) # => Time.new(1981, 8, 1, 22, 35, 0)
+ # Time.new(2012, 8, 29, 22, 35, 0).change(year: 1981, hour: 0) # => Time.new(1981, 8, 29, 0, 0, 0)
def change(options)
new_year = options.fetch(:year, year)
new_month = options.fetch(:month, month)
View
33 activesupport/lib/active_support/hash_with_indifferent_access.rb
@@ -17,7 +17,7 @@ module ActiveSupport
# writing interface (calling <tt>[]=</tt>, <tt>merge</tt>, etc). This
# mapping belongs to the public interface. For example, given
#
- # hash = ActiveSupport::HashWithIndifferentAccess.new(:a => 1)
+ # hash = ActiveSupport::HashWithIndifferentAccess.new(a: 1)
#
# you are guaranteed that the key is returned as a string:
#
@@ -25,7 +25,7 @@ module ActiveSupport
#
# Technically other types of keys are accepted:
#
- # hash = ActiveSupport::HashWithIndifferentAccess.new(:a => 1)
+ # hash = ActiveSupport::HashWithIndifferentAccess.new(a: 1)
# hash[0] = 0
# hash # => {"a"=>1, 0=>0}
#
@@ -35,7 +35,7 @@ module ActiveSupport
#
# Note that core extensions define <tt>Hash#with_indifferent_access</tt>:
#
- # rgb = {:black => '#000000', :white => '#FFFFFF'}.with_indifferent_access
+ # rgb = { black: '#000000', white: '#FFFFFF' }.with_indifferent_access
#
# which may be handy.
class HashWithIndifferentAccess < Hash
@@ -86,9 +86,9 @@ def self.[](*args)
# Assigns a new value to the hash:
#
# hash = ActiveSupport::HashWithIndifferentAccess.new
- # hash[:key] = "value"
+ # hash[:key] = 'value'
#
- # This value can be later fetched using either +:key+ or +"key"+.
+ # This value can be later fetched using either +:key+ or +'key'+.
def []=(key, value)
regular_writer(convert_key(key), convert_value(value))
end
@@ -98,10 +98,10 @@ def []=(key, value)
# Updates the receiver in-place, merging in the hash passed as argument:
#
# hash_1 = ActiveSupport::HashWithIndifferentAccess.new
- # hash_1[:key] = "value"
+ # hash_1[:key] = 'value'
#
# hash_2 = ActiveSupport::HashWithIndifferentAccess.new
- # hash_2[:key] = "New Value!"
+ # hash_2[:key] = 'New Value!'
#
# hash_1.update(hash_2) # => {"key"=>"New Value!"}
#
@@ -120,7 +120,6 @@ def []=(key, value)
# hash_1[:key] = 10
# hash_2['key'] = 12
# hash_1.update(hash_2) { |key, old, new| old + new } # => {"key"=>22}
- #
def update(other_hash)
if other_hash.is_a? HashWithIndifferentAccess
super(other_hash)
@@ -140,10 +139,9 @@ def update(other_hash)
# Checks the hash for a key matching the argument passed in:
#
# hash = ActiveSupport::HashWithIndifferentAccess.new
- # hash["key"] = "value"
+ # hash['key'] = 'value'
# hash.key?(:key) # => true
- # hash.key?("key") # => true
- #
+ # hash.key?('key') # => true
def key?(key)
super(convert_key(key))
end
@@ -158,11 +156,10 @@ def key?(key)
# counters = ActiveSupport::HashWithIndifferentAccess.new
# counters[:foo] = 1
#
- # counters.fetch("foo") # => 1
+ # counters.fetch('foo') # => 1
# counters.fetch(:bar, 0) # => 0
# counters.fetch(:bar) {|key| 0} # => 0
# counters.fetch(:zoo) # => KeyError: key not found: "zoo"
- #
def fetch(key, *extras)
super(convert_key(key), *extras)
end
@@ -170,10 +167,9 @@ def fetch(key, *extras)
# Returns an array of the values at the specified indices:
#
# hash = ActiveSupport::HashWithIndifferentAccess.new
- # hash[:a] = "x"
- # hash[:b] = "y"
- # hash.values_at("a", "b") # => ["x", "y"]
- #
+ # hash[:a] = 'x'
+ # hash[:b] = 'y'
+ # hash.values_at('a', 'b') # => ["x", "y"]
def values_at(*indices)
indices.collect {|key| self[convert_key(key)]}
end
@@ -197,8 +193,7 @@ def merge(hash, &block)
#
# hash = ActiveSupport::HashWithIndifferentAccess.new
# hash['a'] = nil
- # hash.reverse_merge(:a => 0, :b => 1) # => {"a"=>nil, "b"=>1}
- #
+ # hash.reverse_merge(a: 0, b: 1) # => {"a"=>nil, "b"=>1}
def reverse_merge(other_hash)
super(self.class.new_from_hash_copying_default(other_hash))
end
View
22 activesupport/lib/active_support/inflector/transliterate.rb
@@ -8,7 +8,7 @@ module Inflector
# Replaces non-ASCII characters with an ASCII approximation, or if none
# exists, a replacement character which defaults to "?".
#
- # transliterate("Ærøskøbing")
+ # transliterate('Ærøskøbing')
# # => "AEroskobing"
#
# Default approximations are provided for Western/Latin characters,
@@ -30,11 +30,11 @@ module Inflector
# ö: "oe"
#
# # Or set them using Ruby
- # I18n.backend.store_translations(:de, :i18n => {
- # :transliterate => {
- # :rule => {
- # "ü" => "ue",
- # "ö" => "oe"
+ # I18n.backend.store_translations(:de, i18n: {
+ # transliterate: {
+ # rule: {
+ # 'ü' => 'ue',
+ # 'ö' => 'oe'
# }
# }
# })
@@ -43,20 +43,20 @@ module Inflector
# characters to ASCII approximations as shown above, or, for more complex
# requirements, a Proc:
#
- # I18n.backend.store_translations(:de, :i18n => {
- # :transliterate => {
- # :rule => lambda {|string| MyTransliterator.transliterate(string)}
+ # I18n.backend.store_translations(:de, i18n: {
+ # transliterate: {
+ # rule: lambda { |string| MyTransliterator.transliterate(string) }
# }
# })
#
# Now you can have different transliterations for each locale:
#
# I18n.locale = :en
- # transliterate("Jürgen")
+ # transliterate('Jürgen')
# # => "Jurgen"
#
# I18n.locale = :de
- # transliterate("Jürgen")
+ # transliterate('Jürgen')
# # => "Juergen"
def transliterate(string, replacement = "?")
I18n.transliterate(ActiveSupport::Multibyte::Unicode.normalize(
View
16 activesupport/lib/active_support/notifications.rb
@@ -10,13 +10,13 @@ module ActiveSupport
#
# To instrument an event you just need to do:
#
- # ActiveSupport::Notifications.instrument("render", :extra => :information) do
- # render :text => "Foo"
+ # ActiveSupport::Notifications.instrument('render', extra: :information) do
+ # render text: 'Foo'
# end
#
# That executes the block first and notifies all subscribers once done.
#
- # In the example above "render" is the name of the event, and the rest is called
+ # In the example above +render+ is the name of the event, and the rest is called
# the _payload_. The payload is a mechanism that allows instrumenters to pass
# extra information to subscribers. Payloads consist of a hash whose contents
# are arbitrary and generally depend on the event.
@@ -28,21 +28,21 @@ module ActiveSupport
#
# events = []
#
- # ActiveSupport::Notifications.subscribe("render") do |*args|
+ # ActiveSupport::Notifications.subscribe('render') do |*args|
# events << ActiveSupport::Notifications::Event.new(*args)
# end
#
# That code returns right away, you are just subscribing to "render" events.
# The block is saved and will be called whenever someone instruments "render":
#
- # ActiveSupport::Notifications.instrument("render", :extra => :information) do
- # render :text => "Foo"
+ # ActiveSupport::Notifications.instrument('render', extra: :information) do
+ # render text: 'Foo'
# end
#
# event = events.first
# event.name # => "render"
# event.duration # => 10 (in milliseconds)
- # event.payload # => { :extra => :information }
+ # event.payload # => { extra: :information }
#
# The block in the <tt>subscribe</tt> call gets the name of the event, start
# timestamp, end timestamp, a string with a unique identifier for that event
@@ -63,7 +63,7 @@ module ActiveSupport
# module ActionController
# class PageRequest
# def call(name, started, finished, unique_id, payload)
- # Rails.logger.debug ["notification:", name, started, finished, unique_id, payload].join(" ")
+ # Rails.logger.debug ['notification:', name, started, finished, unique_id, payload].join(' ')
# end
# end
# end
View
20 activesupport/lib/active_support/number_helper.rb
@@ -126,13 +126,13 @@ module NumberHelper
# ==== Examples
#
# number_to_phone(5551234) # => 555-1234
- # number_to_phone("5551234") # => 555-1234
+ # number_to_phone('5551234') # => 555-1234
# number_to_phone(1235551234) # => 123-555-1234
# number_to_phone(1235551234, area_code: true) # => (123) 555-1234
# number_to_phone(1235551234, delimiter: ' ') # => 123 555 1234
# number_to_phone(1235551234, area_code: true, extension: 555) # => (123) 555-1234 x 555
# number_to_phone(1235551234, country_code: 1) # => +1-123-555-1234
- # number_to_phone("123a456") # => 123a456
+ # number_to_phone('123a456') # => 123a456
#
# number_to_phone(1235551234, country_code: 1, extension: 1343, delimiter: '.')
# # => +1.123.555.1234 x 1343
@@ -249,7 +249,7 @@ def number_to_currency(number, options = {})
# number_to_percentage(100, precision: 0) # => 100%
# number_to_percentage(1000, delimiter: '.', separator: ,') # => 1.000,000%
# number_to_percentage(302.24398923423, precision: 5) # => 302.24399%
- # number_to_percentage(1000, :locale => :fr) # => 1 000,000%
+ # number_to_percentage(1000, locale: :fr) # => 1 000,000%
# number_to_percentage('98a') # => 98a%
# number_to_percentage(100, format: '%n %') # => 100 %
def number_to_percentage(number, options = {})
@@ -524,7 +524,7 @@ def number_to_human_size(number, options = {})
# ==== Custom Unit Quantifiers
#
# You can also use your own custom unit quantifiers:
- # number_to_human(500000, :units => {:unit => "ml", :thousand => "lt"}) # => "500 lt"
+ # number_to_human(500000, units: { unit: 'ml', thousand: 'lt' }) # => "500 lt"
#
# If in your I18n locale you have:
#
@@ -542,12 +542,12 @@ def number_to_human_size(number, options = {})
#
# Then you could do:
#
- # number_to_human(543934, :units => :distance) # => "544 kilometers"
- # number_to_human(54393498, :units => :distance) # => "54400 kilometers"
- # number_to_human(54393498000, :units => :distance) # => "54.4 gazillion-distance"
- # number_to_human(343, :units => :distance, :precision => 1) # => "300 meters"
- # number_to_human(1, :units => :distance) # => "1 meter"
- # number_to_human(0.34, :units => :distance) # => "34 centimeters"
+ # number_to_human(543934, units: :distance) # => "544 kilometers"
+ # number_to_human(54393498, units: :distance) # => "54400 kilometers"
+ # number_to_human(54393498000, units: :distance) # => "54.4 gazillion-distance"
+ # number_to_human(343, units: :distance, precision: 1) # => "300 meters"
+ # number_to_human(1, units: :distance) # => "1 meter"
+ # number_to_human(0.34, units: :distance) # => "34 centimeters"
def number_to_human(number, options = {})
options = options.symbolize_keys
View
6 activesupport/lib/active_support/rescuable.rb
@@ -31,11 +31,11 @@ module ClassMethods
# any.
#
# class ApplicationController < ActionController::Base
- # rescue_from User::NotAuthorized, :with => :deny_access # self defined exception
- # rescue_from ActiveRecord::RecordInvalid, :with => :show_errors
+ # rescue_from User::NotAuthorized, with: :deny_access # self defined exception
+ # rescue_from ActiveRecord::RecordInvalid, with: :show_errors
#
# rescue_from 'MyAppError::Base' do |exception|
- # render :xml => exception, :status => 500
+ # render xml: exception, status: 500
# end
#
# protected
Please sign in to comment.
Something went wrong with that request. Please try again.