aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-07-30 02:35:24 +0200
committerXavier Noria <fxn@hashref.com>2010-07-30 02:35:24 +0200
commitccd45618ed9a629c9535a5ff84ef5c238befa4ab (patch)
tree0a582bf695dce01240762d2b8516efde43bc3515 /activesupport/lib/active_support/core_ext
parent3c3ff1377d17b584dd14d85c7cecab59ddff2679 (diff)
parent755af497555fde16db86f7e51f6462b0aca79b49 (diff)
downloadrails-ccd45618ed9a629c9535a5ff84ef5c238befa4ab.tar.gz
rails-ccd45618ed9a629c9535a5ff84ef5c238befa4ab.tar.bz2
rails-ccd45618ed9a629c9535a5ff84ef5c238befa4ab.zip
Merge remote branch 'rails/master'
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/array/uniq_by.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/array/wrap.rb13
-rw-r--r--activesupport/lib/active_support/core_ext/enumerable.rb3
-rw-r--r--activesupport/lib/active_support/core_ext/string/inflections.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/string/multibyte.rb10
5 files changed, 18 insertions, 11 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/uniq_by.rb b/activesupport/lib/active_support/core_ext/array/uniq_by.rb
index a09b2302fd..bd5c7a187f 100644
--- a/activesupport/lib/active_support/core_ext/array/uniq_by.rb
+++ b/activesupport/lib/active_support/core_ext/array/uniq_by.rb
@@ -2,7 +2,7 @@ class Array
# Return an unique array based on the criteria given as a proc.
#
# [1, 2, 3, 4].uniq_by { |i| i.odd? }
- # #=> [1, 2]
+ # # => [1, 2]
#
def uniq_by
hash, array = {}, []
diff --git a/activesupport/lib/active_support/core_ext/array/wrap.rb b/activesupport/lib/active_support/core_ext/array/wrap.rb
index e211bdeeca..09a1c2e5a1 100644
--- a/activesupport/lib/active_support/core_ext/array/wrap.rb
+++ b/activesupport/lib/active_support/core_ext/array/wrap.rb
@@ -1,9 +1,14 @@
class Array
- # Wraps the object in an Array unless it's an Array. Converts the
- # object to an Array using #to_ary if it implements that.
+ # <tt>Array.wrap</tt> is like <tt>Kernel#Array</tt> except:
#
- # It differs with Array() in that it does not call +to_a+ on
- # the argument:
+ # * If the argument responds to +to_ary+ the method is invoked. <tt>Kernel#Array</tt>
+ # moves on to try +to_a+ if the returned value is +nil+, but <tt>Arraw.wrap</tt> returns
+ # such a +nil+ right away.
+ # * If the returned value from +to_ary+ is neither +nil+ nor an +Array+ object, <tt>Kernel#Array</tt>
+ # raises an exception, while <tt>Array.wrap</tt> does not, it just returns the value.
+ # * It does not call +to_a+ on the argument, though special-cases +nil+ to return an empty array.
+ #
+ # The last point is particularly worth comparing for some enumerables:
#
# Array(:foo => :bar) # => [[:foo, :bar]]
# Array.wrap(:foo => :bar) # => [{:foo => :bar}]
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb
index d0821a7c68..f76ed401cd 100644
--- a/activesupport/lib/active_support/core_ext/enumerable.rb
+++ b/activesupport/lib/active_support/core_ext/enumerable.rb
@@ -66,7 +66,8 @@ module Enumerable
# +memo+ to the block. Handy for building up hashes or
# reducing collections down to one object. Examples:
#
- # %w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } #=> {'foo' => 'FOO', 'bar' => 'BAR'}
+ # %w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase }
+ # # => {'foo' => 'FOO', 'bar' => 'BAR'}
#
# *Note* that you can't use immutable objects like numbers, true or false as
# the memo. You would think the following returns 120, but since the memo is
diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb
index 66c4034781..f33e4959f9 100644
--- a/activesupport/lib/active_support/core_ext/string/inflections.rb
+++ b/activesupport/lib/active_support/core_ext/string/inflections.rb
@@ -1,3 +1,4 @@
+require 'active_support/inflector/methods'
# String inflections define new methods on the String class to transform names for different purposes.
# For instance, you can figure out the name of a database from the name of a class.
#
diff --git a/activesupport/lib/active_support/core_ext/string/multibyte.rb b/activesupport/lib/active_support/core_ext/string/multibyte.rb
index 16ccd36458..0b974f5e0a 100644
--- a/activesupport/lib/active_support/core_ext/string/multibyte.rb
+++ b/activesupport/lib/active_support/core_ext/string/multibyte.rb
@@ -12,11 +12,11 @@ class String
# class. If the proxy class doesn't respond to a certain method, it's forwarded to the encapsuled string.
#
# name = 'Claus Müller'
- # name.reverse #=> "rell??M sualC"
- # name.length #=> 13
+ # name.reverse # => "rell??M sualC"
+ # name.length # => 13
#
- # name.mb_chars.reverse.to_s #=> "rellüM sualC"
- # name.mb_chars.length #=> 12
+ # name.mb_chars.reverse.to_s # => "rellüM sualC"
+ # name.mb_chars.length # => 12
#
# In Ruby 1.9 and newer +mb_chars+ returns +self+ because String is (mostly) encoding aware. This means that
# it becomes easy to run one version of your code on multiple Ruby versions.
@@ -26,7 +26,7 @@ class String
# All the methods on the Chars proxy which normally return a string will return a Chars object. This allows
# method chaining on the result of any of these methods.
#
- # name.mb_chars.reverse.length #=> 12
+ # name.mb_chars.reverse.length # => 12
#
# == Interoperability and configuration
#