aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2011-05-14 11:21:27 +0200
committerXavier Noria <fxn@hashref.com>2011-05-14 11:21:27 +0200
commitd49113023676fbf0b6653730f5bde759990caede (patch)
treede8a47655ad3a1fa1e73dbc307ec9b806637b3ec /activesupport/lib/active_support/core_ext
parentdb886c817c3620ceaa68a988947e49e5219532fd (diff)
parente5524d538c0d0f39d655a78fc45d2122c0ff2f2a (diff)
downloadrails-d49113023676fbf0b6653730f5bde759990caede.tar.gz
rails-d49113023676fbf0b6653730f5bde759990caede.tar.bz2
rails-d49113023676fbf0b6653730f5bde759990caede.zip
Merge branch 'master' of git://github.com/lifo/docrails
Conflicts: actionpack/lib/action_view/helpers/date_helper.rb railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/array/conversions.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/array/random_access.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/array/uniq_by.rb5
-rw-r--r--activesupport/lib/active_support/core_ext/date_time/conversions.rb16
-rw-r--r--activesupport/lib/active_support/core_ext/hash/slice.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/integer/inflections.rb11
-rw-r--r--activesupport/lib/active_support/core_ext/object/blank.rb6
-rw-r--r--activesupport/lib/active_support/core_ext/object/with_options.rb13
-rw-r--r--activesupport/lib/active_support/core_ext/string/behavior.rb3
-rw-r--r--activesupport/lib/active_support/core_ext/string/exclude.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/string/inquiry.rb2
11 files changed, 35 insertions, 31 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb
index baefa9cae4..3b22e8b4f9 100644
--- a/activesupport/lib/active_support/core_ext/array/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -37,12 +37,12 @@ class Array
# Converts a collection of elements into a formatted string by calling
# <tt>to_s</tt> on all elements and joining them:
#
- # Blog.find(:all).to_formatted_s # => "First PostSecond PostThird Post"
+ # Blog.all.to_formatted_s # => "First PostSecond PostThird Post"
#
# Adding in the <tt>:db</tt> argument as the format yields a prettier
# output:
#
- # Blog.find(:all).to_formatted_s(:db) # => "First Post,Second Post,Third Post"
+ # Blog.all.to_formatted_s(:db) # => "First Post,Second Post,Third Post"
def to_formatted_s(format = :default)
case format
when :db
diff --git a/activesupport/lib/active_support/core_ext/array/random_access.rb b/activesupport/lib/active_support/core_ext/array/random_access.rb
index 9eba4642b8..bb1807a68a 100644
--- a/activesupport/lib/active_support/core_ext/array/random_access.rb
+++ b/activesupport/lib/active_support/core_ext/array/random_access.rb
@@ -7,7 +7,7 @@ class Array
#
# [1,2,3,4,5,6].sample # => 4
# [1,2,3,4,5,6].sample(3) # => [2, 4, 5]
- # [1,2,3,4,5,6].sample(-3) # => ArgumentError: negative sample number
+ # [1,2,3,4,5,6].sample(-3) # => ArgumentError: negative array size
# [].sample # => nil
# [].sample(3) # => []
def sample(n=nil)
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 bd5c7a187f..9c5f97b0e9 100644
--- a/activesupport/lib/active_support/core_ext/array/uniq_by.rb
+++ b/activesupport/lib/active_support/core_ext/array/uniq_by.rb
@@ -1,8 +1,7 @@
class Array
- # Return an unique array based on the criteria given as a proc.
+ # Returns an unique array based on the criteria given as a +Proc+.
#
- # [1, 2, 3, 4].uniq_by { |i| i.odd? }
- # # => [1, 2]
+ # [1, 2, 3, 4].uniq_by { |i| i.odd? } # => [1, 2]
#
def uniq_by
hash, array = {}, []
diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
index 21b84b994b..ca899c714c 100644
--- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -51,25 +51,25 @@ class DateTime
utc? && alternate_utc_string || ActiveSupport::TimeZone.seconds_to_utc_offset(utc_offset, colon)
end
- # Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005 14:30:00 +0000"
+ # Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005 14:30:00 +0000".
def readable_inspect
to_s(:rfc822)
end
alias_method :default_inspect, :inspect
alias_method :inspect, :readable_inspect
- # Converts self to a Ruby Date object; time portion is discarded
+ # Converts self to a Ruby Date object; time portion is discarded.
def to_date
::Date.new(year, month, day)
end unless instance_methods(false).include?(:to_date)
- # Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class
- # If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time
+ # Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class.
+ # If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time.
def to_time
self.offset == 0 ? ::Time.utc_time(year, month, day, hour, min, sec, sec_fraction * (RUBY_VERSION < '1.9' ? 86400000000 : 1000000)) : self
end
- # To be able to keep Times, Dates and DateTimes interchangeable on conversions
+ # To be able to keep Times, Dates and DateTimes interchangeable on conversions.
def to_datetime
self
end unless instance_methods(false).include?(:to_datetime)
@@ -79,17 +79,17 @@ class DateTime
civil(year, month, day, hour, min, sec, offset)
end
- # Converts datetime to an appropriate format for use in XML
+ # Converts datetime to an appropriate format for use in XML.
def xmlschema
strftime("%Y-%m-%dT%H:%M:%S%Z")
end unless instance_methods(false).include?(:xmlschema)
- # Converts self to a floating-point number of seconds since the Unix epoch
+ # Converts self to a floating-point number of seconds since the Unix epoch.
def to_f
seconds_since_unix_epoch.to_f
end
- # Converts self to an integer number of seconds since the Unix epoch
+ # Converts self to an integer number of seconds since the Unix epoch.
def to_i
seconds_since_unix_epoch.to_i
end
diff --git a/activesupport/lib/active_support/core_ext/hash/slice.rb b/activesupport/lib/active_support/core_ext/hash/slice.rb
index e4a864c20f..d7fb2da0fb 100644
--- a/activesupport/lib/active_support/core_ext/hash/slice.rb
+++ b/activesupport/lib/active_support/core_ext/hash/slice.rb
@@ -21,7 +21,7 @@ class Hash
# Replaces the hash with only the given keys.
# Returns a hash contained the removed key/value pairs
- # {:a => 1, :b => 2, :c => 3, :d => 4}.slice!(:a, :b) # => {:c => 3, :d =>4}
+ # {:a => 1, :b => 2, :c => 3, :d => 4}.slice!(:a, :b) # => {:c => 3, :d => 4}
def slice!(*keys)
keys = keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
omit = slice(*self.keys - keys)
diff --git a/activesupport/lib/active_support/core_ext/integer/inflections.rb b/activesupport/lib/active_support/core_ext/integer/inflections.rb
index e81e7af436..0e606056c0 100644
--- a/activesupport/lib/active_support/core_ext/integer/inflections.rb
+++ b/activesupport/lib/active_support/core_ext/integer/inflections.rb
@@ -4,10 +4,13 @@ class Integer
# Ordinalize turns a number into an ordinal string used to denote the
# position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
#
- # 1.ordinalize # => "1st"
- # 2.ordinalize # => "2nd"
- # 1002.ordinalize # => "1002nd"
- # 1003.ordinalize # => "1003rd"
+ # 1.ordinalize # => "1st"
+ # 2.ordinalize # => "2nd"
+ # 1002.ordinalize # => "1002nd"
+ # 1003.ordinalize # => "1003rd"
+ # -11.ordinalize # => "-11th"
+ # -1001.ordinalize # => "-1001st"
+ #
def ordinalize
ActiveSupport::Inflector.ordinalize(self)
end
diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb
index 20085c4fb3..fb5abf2aa5 100644
--- a/activesupport/lib/active_support/core_ext/object/blank.rb
+++ b/activesupport/lib/active_support/core_ext/object/blank.rb
@@ -1,14 +1,14 @@
class Object
# An object is blank if it's false, empty, or a whitespace string.
- # For example, "", " ", +nil+, [], and {} are blank.
+ # For example, "", " ", +nil+, [], and {} are all blank.
#
# This simplifies:
#
- # if !address.nil? && !address.empty?
+ # if address.nil? || address.empty?
#
# ...to:
#
- # if !address.blank?
+ # if address.blank?
def blank?
respond_to?(:empty?) ? empty? : !self
end
diff --git a/activesupport/lib/active_support/core_ext/object/with_options.rb b/activesupport/lib/active_support/core_ext/object/with_options.rb
index c23afabfdb..1397142c04 100644
--- a/activesupport/lib/active_support/core_ext/object/with_options.rb
+++ b/activesupport/lib/active_support/core_ext/object/with_options.rb
@@ -7,7 +7,7 @@ class Object
# provided. Each method called on the block variable must take an options
# hash as its final argument.
#
- # Without with_options, this code contains duplication:
+ # Without <tt>with_options></tt>, this code contains duplication:
#
# class Account < ActiveRecord::Base
# has_many :customers, :dependent => :destroy
@@ -16,7 +16,7 @@ class Object
# has_many :expenses, :dependent => :destroy
# end
#
- # Using with_options, we can remove the duplication:
+ # Using <tt>with_options</tt>, we can remove the duplication:
#
# class Account < ActiveRecord::Base
# with_options :dependent => :destroy do |assoc|
@@ -29,11 +29,14 @@ class Object
#
# It can also be used with an explicit receiver:
#
- # map.with_options :controller => "people" do |people|
- # people.connect "/people", :action => "index"
- # people.connect "/people/:id", :action => "show"
+ # I18n.with_options :locale => user.locale, :scope => "newsletter" do |i18n|
+ # subject i18n.t :subject
+ # 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
diff --git a/activesupport/lib/active_support/core_ext/string/behavior.rb b/activesupport/lib/active_support/core_ext/string/behavior.rb
index 9d45fbca45..4aa960039b 100644
--- a/activesupport/lib/active_support/core_ext/string/behavior.rb
+++ b/activesupport/lib/active_support/core_ext/string/behavior.rb
@@ -1,6 +1,5 @@
class String
- # Enable more predictable duck-typing on String-like classes. See
- # Object#acts_like?.
+ # Enable more predictable duck-typing on String-like classes. See <tt>Object#acts_like?</tt>.
def acts_like_string?
true
end
diff --git a/activesupport/lib/active_support/core_ext/string/exclude.rb b/activesupport/lib/active_support/core_ext/string/exclude.rb
index 5ca268b953..5e184ec1b3 100644
--- a/activesupport/lib/active_support/core_ext/string/exclude.rb
+++ b/activesupport/lib/active_support/core_ext/string/exclude.rb
@@ -1,5 +1,5 @@
class String
- # The inverse of String#include?. Returns true if the string does not include the other string.
+ # The inverse of <tt>String#include?</tt>. Returns true if the string does not include the other string.
def exclude?(string)
!include?(string)
end
diff --git a/activesupport/lib/active_support/core_ext/string/inquiry.rb b/activesupport/lib/active_support/core_ext/string/inquiry.rb
index 604f3bf4dc..5f0a017de6 100644
--- a/activesupport/lib/active_support/core_ext/string/inquiry.rb
+++ b/activesupport/lib/active_support/core_ext/string/inquiry.rb
@@ -1,7 +1,7 @@
require 'active_support/string_inquirer'
class String
- # Wraps the current string in the ActiveSupport::StringInquirer class,
+ # Wraps the current string in the <tt>ActiveSupport::StringInquirer</tt> class,
# which gives you a prettier way to test for equality. Example:
#
# env = "production".inquiry