From 6372d23616b13c62c7a12efa89f958b334dd66ae Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Wed, 4 May 2011 15:51:47 -0300 Subject: Fix punctuation errors. --- .../lib/active_support/core_ext/date_time/conversions.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') 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 -- cgit v1.2.3 From a4b6e3d9be338e93320606f7cb14759b26ced8df Mon Sep 17 00:00:00 2001 From: Caley Woods Date: Fri, 6 May 2011 08:23:12 -0700 Subject: Small edit to the if statement simplification for blank? on the Object class. An Object doesn't need to be nil and empty to be blank? just one or the other. --- activesupport/lib/active_support/core_ext/object/blank.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index 20085c4fb3..d756b8cca0 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -4,7 +4,7 @@ class Object # # This simplifies: # - # if !address.nil? && !address.empty? + # if !address.nil? || !address.empty? # # ...to: # -- cgit v1.2.3 From ef2738472d5c9e6e561d97c9fadbad6b3863017f Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 6 May 2011 17:30:00 +0200 Subject: Revert "Small edit to the if statement simplification for blank? on the Object class. An Object doesn't need to be nil and empty to be blank? just one or the other." Reason: the original code is correct, see !nil && !empty -> !(nil || empty) -> !blank That said, this example has too many negations for my linking. Think should be revised to be more positive and straightforward to read. This reverts commit a4b6e3d9be338e93320606f7cb14759b26ced8df. --- activesupport/lib/active_support/core_ext/object/blank.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index d756b8cca0..20085c4fb3 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -4,7 +4,7 @@ class Object # # This simplifies: # - # if !address.nil? || !address.empty? + # if !address.nil? && !address.empty? # # ...to: # -- cgit v1.2.3 From 162bf8ffb1bef8729f22e2adfae7b1a5d096173d Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 7 May 2011 12:13:38 +0530 Subject: revises comment for blank? method --- activesupport/lib/active_support/core_ext/object/blank.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') 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 -- cgit v1.2.3 From 7194b393a611727fb36e8f586910e75db1bae746 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 7 May 2011 18:07:42 +0530 Subject: fix comment alignment --- activesupport/lib/active_support/core_ext/array/uniq_by.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') 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 = {}, [] -- cgit v1.2.3 From 3056b3379b8ca5d859e8237c46d6abe7f67a5d09 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 7 May 2011 18:08:13 +0530 Subject: use new AR calls in examples --- activesupport/lib/active_support/core_ext/array/conversions.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') 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 # to_s 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 :db 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 -- cgit v1.2.3 From 6e83330590eafc52aa65ed17f8764414fc16346a Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 7 May 2011 18:09:20 +0530 Subject: fixes incorrect error message for sample method --- activesupport/lib/active_support/core_ext/array/random_access.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext') 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) -- cgit v1.2.3 From ffb70cf256e25965230af0e15ccb85e6e9f80bac Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 7 May 2011 20:20:28 +0530 Subject: minor fixes --- activesupport/lib/active_support/core_ext/string/behavior.rb | 3 +-- activesupport/lib/active_support/core_ext/string/exclude.rb | 2 +- activesupport/lib/active_support/core_ext/string/inquiry.rb | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') 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 Object#acts_like?. 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 String#include?. 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 ActiveSupport::StringInquirer class, # which gives you a prettier way to test for equality. Example: # # env = "production".inquiry -- cgit v1.2.3 From 448845cd0dab1018f1bfc11dde5bbcd129abe93f Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 7 May 2011 21:18:03 +0530 Subject: replaced eg using old router api with the one in the guides. Add info on nesting with_options --- .../lib/active_support/core_ext/object/with_options.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') 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 with_options>, 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 with_options, 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 # + # with_options 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 -- cgit v1.2.3 From eef2060879efb665524b9b61918267ef9a4e650d Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 8 May 2011 23:43:46 +0530 Subject: included examples for negative ordinalize --- .../lib/active_support/core_ext/integer/inflections.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') 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 -- cgit v1.2.3 From ab880b9eb0aab83e9c000a89e9f0ca636a8b9f78 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Tue, 10 May 2011 20:55:31 -0300 Subject: Follow code conventions on docs --- activesupport/lib/active_support/core_ext/hash/slice.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext') 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) -- cgit v1.2.3