From 4dd84c8db06ddb56468401a478399c995c9604c1 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 15 Apr 2011 14:08:37 -0300 Subject: Improved Array#sample documentation --- activesupport/lib/active_support/core_ext/array/random_access.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') 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 ab1fa7cd5b..0bf510e39a 100644 --- a/activesupport/lib/active_support/core_ext/array/random_access.rb +++ b/activesupport/lib/active_support/core_ext/array/random_access.rb @@ -1,7 +1,9 @@ class Array # Backport of Array#sample based on Marc-Andre Lafortune's https://github.com/marcandre/backports/ # Returns a random element or +n+ random elements from the array. - # If the array is empty and +n+ is nil, returns nil. if +n+ is passed, returns []. + # If the array is empty and +n+ is nil, returns nil. + # If +n+ is passed and its value is less than 0, it raises an +ArgumentError+ exception. + # If the value of +n+ is equal or greater than 0 it returns []. # # [1,2,3,4,5,6].sample # => 4 # [1,2,3,4,5,6].sample(3) # => [2, 4, 5] -- cgit v1.2.3 From 91761b775ce1f028486dc3483904795e9c028ed6 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 15 Apr 2011 14:13:10 -0300 Subject: Added an example of exception situation on Array#sample docs --- activesupport/lib/active_support/core_ext/array/random_access.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'activesupport/lib') 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 0bf510e39a..9eba4642b8 100644 --- a/activesupport/lib/active_support/core_ext/array/random_access.rb +++ b/activesupport/lib/active_support/core_ext/array/random_access.rb @@ -5,10 +5,11 @@ class Array # If +n+ is passed and its value is less than 0, it raises an +ArgumentError+ exception. # If the value of +n+ is equal or greater than 0 it returns []. # - # [1,2,3,4,5,6].sample # => 4 - # [1,2,3,4,5,6].sample(3) # => [2, 4, 5] - # [].sample # => nil - # [].sample(3) # => [] + # [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 + # [].sample # => nil + # [].sample(3) # => [] def sample(n=nil) return self[Kernel.rand(size)] if n.nil? n = n.to_int -- cgit v1.2.3 From bd302542d0993a4965c870de607051748b6de0be Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Sun, 17 Apr 2011 19:36:56 -0300 Subject: Documented NilClass#blank? --- activesupport/lib/active_support/core_ext/object/blank.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index d0c1ea8326..76450a9238 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -37,7 +37,11 @@ class Object end end -class NilClass #:nodoc: +class NilClass + # Instances of NilClass are always blank + # Example: + # + # nil.blank? => true def blank? true end -- cgit v1.2.3 From a48d2a7a070540b60d50b14a201ffeba02e390f8 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Sun, 17 Apr 2011 19:38:32 -0300 Subject: Documented FalseClass#blank? --- activesupport/lib/active_support/core_ext/object/blank.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index 76450a9238..57944bd271 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -47,7 +47,11 @@ class NilClass end end -class FalseClass #:nodoc: +class FalseClass + # Instances of FalseClass are always blank + # Example: + # + # false.blank? => true def blank? true end -- cgit v1.2.3 From c49799923098b63e906af955dc077cb24caeb659 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Sun, 17 Apr 2011 19:39:40 -0300 Subject: Documented TrueClass#blank? --- activesupport/lib/active_support/core_ext/object/blank.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index 57944bd271..764d0666fd 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -57,7 +57,11 @@ class FalseClass end end -class TrueClass #:nodoc: +class TrueClass + # Instances of TrueClass are never blank + # Example: + # + # true.blank? => false def blank? false end -- cgit v1.2.3 From ceeed213a96d2f893838f9304b3953a1fc727cfc Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Sun, 17 Apr 2011 19:42:53 -0300 Subject: Documented Array#blank? --- activesupport/lib/active_support/core_ext/object/blank.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index 764d0666fd..d6f0056ba4 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -67,7 +67,12 @@ class TrueClass end end -class Array #:nodoc: +class Array + # An array is blank if it's empty + # For example: + # + # [].blank? => true + # [1,2,3].blank? => false alias_method :blank?, :empty? end -- cgit v1.2.3 From b14b058be863e5a557191c9b403cc7ebc77951c9 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Sun, 17 Apr 2011 19:44:34 -0300 Subject: Documented Hash#blank? --- activesupport/lib/active_support/core_ext/object/blank.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index d6f0056ba4..8cef3e87ea 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -76,7 +76,12 @@ class Array alias_method :blank?, :empty? end -class Hash #:nodoc: +class Hash + # A hash is blank if it's empty + # For example: + # + # {}.blank? => true + # {:key => 'value'}.blank? => false alias_method :blank?, :empty? end -- cgit v1.2.3 From d0635b6ad43dd08fe2fc505388b4cd229e25845f Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Sun, 17 Apr 2011 19:47:46 -0300 Subject: Documented String#blank? --- activesupport/lib/active_support/core_ext/object/blank.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index 8cef3e87ea..5cf49e2cbf 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -85,7 +85,13 @@ class Hash alias_method :blank?, :empty? end -class String #:nodoc: +class String + # A string is blank if it's empty or contains whitespaces only + # For example: + # + # "".blank? => true + # " ".blank? => true + # " something here ".blank? => false def blank? self !~ /\S/ end -- cgit v1.2.3 From 0675047d79912b11a387941e7968d4a651f0cd48 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Sun, 17 Apr 2011 20:12:39 -0300 Subject: Formatting examples --- .../lib/active_support/core_ext/object/blank.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index 5cf49e2cbf..be22d7534e 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -39,7 +39,8 @@ end class NilClass # Instances of NilClass are always blank - # Example: + # + # === Example # # nil.blank? => true def blank? @@ -49,7 +50,8 @@ end class FalseClass # Instances of FalseClass are always blank - # Example: + # + # === Example # # false.blank? => true def blank? @@ -59,7 +61,8 @@ end class TrueClass # Instances of TrueClass are never blank - # Example: + # + # === Example # # true.blank? => false def blank? @@ -69,7 +72,8 @@ end class Array # An array is blank if it's empty - # For example: + # + # === Examples # # [].blank? => true # [1,2,3].blank? => false @@ -78,7 +82,8 @@ end class Hash # A hash is blank if it's empty - # For example: + # + # === Examples # # {}.blank? => true # {:key => 'value'}.blank? => false @@ -87,7 +92,8 @@ end class String # A string is blank if it's empty or contains whitespaces only - # For example: + # + # === Examples # # "".blank? => true # " ".blank? => true -- cgit v1.2.3 From bb626e785a9ad32d025e429af24654f2af662d09 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Sun, 17 Apr 2011 20:22:53 -0300 Subject: Docs for NilClass#try --- activesupport/lib/active_support/core_ext/object/try.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb index 04619124a1..341a6237cb 100644 --- a/activesupport/lib/active_support/core_ext/object/try.rb +++ b/activesupport/lib/active_support/core_ext/object/try.rb @@ -34,7 +34,19 @@ class Object end end -class NilClass #:nodoc: +class NilClass + # Instances of NilClass return always +nil+ + # It becomes specially helpful when navigating through associations that may return nil + # + # === Examples + # + # nil.try(:name) => nil + # + # Without try + # @person && @person.children.first && @person.children.first.name + # + # With try + # @person.try(:children).try(:first).try(:name) def try(*args) nil end -- cgit v1.2.3 From 49e7555a5ed5463fdf13474259e285d41f171da8 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Sun, 17 Apr 2011 20:38:50 -0300 Subject: Docs for +duplicable?+ --- .../active_support/core_ext/object/duplicable.rb | 32 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/duplicable.rb b/activesupport/lib/active_support/core_ext/object/duplicable.rb index b05325790c..0f9129d0b6 100644 --- a/activesupport/lib/active_support/core_ext/object/duplicable.rb +++ b/activesupport/lib/active_support/core_ext/object/duplicable.rb @@ -22,25 +22,49 @@ class Object end end -class NilClass #:nodoc: +class NilClass + # Instances of NilClass are not duplicable + # + # === Example + # + # nil.duplicable? # => false + # nil.dup # => TypeError: can't dup NilClass def duplicable? false end end -class FalseClass #:nodoc: +class FalseClass + # Instances of FalseClass are not duplicable + # + # === Example + # + # false.duplicable? # => false + # false.dup # => TypeError: can't dup FalseClass def duplicable? false end end -class TrueClass #:nodoc: +class TrueClass + # Instances of TrueClass are not duplicable + # + # === Example + # + # true.duplicable? # => false + # true.dup # => TypeError: can't dup TrueClass def duplicable? false end end -class Symbol #:nodoc: +class Symbol + # Symbols are not duplicable + # + # === Example + # + # :my_symbol.duplicable? # => false + # :my_symbol.dup # => TypeError: can't dup Symbol def duplicable? false end -- cgit v1.2.3 From 9dfc2153270dcaa2f978ef52fbece99efc150bbc Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Sun, 17 Apr 2011 20:40:33 -0300 Subject: Formatting docs --- .../lib/active_support/core_ext/object/blank.rb | 20 ++++++++++---------- .../lib/active_support/core_ext/object/try.rb | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index be22d7534e..b92277f427 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -42,7 +42,7 @@ class NilClass # # === Example # - # nil.blank? => true + # nil.blank? # => true def blank? true end @@ -53,7 +53,7 @@ class FalseClass # # === Example # - # false.blank? => true + # false.blank? # => true def blank? true end @@ -64,7 +64,7 @@ class TrueClass # # === Example # - # true.blank? => false + # true.blank? # => false def blank? false end @@ -75,8 +75,8 @@ class Array # # === Examples # - # [].blank? => true - # [1,2,3].blank? => false + # [].blank? # => true + # [1,2,3].blank? # => false alias_method :blank?, :empty? end @@ -85,8 +85,8 @@ class Hash # # === Examples # - # {}.blank? => true - # {:key => 'value'}.blank? => false + # {}.blank? # => true + # {:key => 'value'}.blank? # => false alias_method :blank?, :empty? end @@ -95,9 +95,9 @@ class String # # === Examples # - # "".blank? => true - # " ".blank? => true - # " something here ".blank? => false + # "".blank? # => true + # " ".blank? # => true + # " something here ".blank? # => false def blank? self !~ /\S/ end diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb index 341a6237cb..0977ac51e8 100644 --- a/activesupport/lib/active_support/core_ext/object/try.rb +++ b/activesupport/lib/active_support/core_ext/object/try.rb @@ -40,7 +40,7 @@ class NilClass # # === Examples # - # nil.try(:name) => nil + # nil.try(:name) # => nil # # Without try # @person && @person.children.first && @person.children.first.name -- cgit v1.2.3 From af41d5540b0bab8c8cee8cbc7cbfb8fab0676518 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Mon, 18 Apr 2011 09:33:00 -0300 Subject: Fixed docs for NilClass#try --- activesupport/lib/active_support/core_ext/object/try.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb index 0977ac51e8..c2a3abbc7c 100644 --- a/activesupport/lib/active_support/core_ext/object/try.rb +++ b/activesupport/lib/active_support/core_ext/object/try.rb @@ -9,12 +9,12 @@ class Object # # ==== Examples # - # Without try + # Without +try+ # @person && @person.name # or # @person ? @person.name : nil # - # With try + # With +try+ # @person.try(:name) # # +try+ also accepts arguments and/or a block, for the method it is trying @@ -35,17 +35,17 @@ class Object end class NilClass - # Instances of NilClass return always +nil+ - # It becomes specially helpful when navigating through associations that may return nil + # Instances of +NilClass+ return always +nil+. + # It becomes specially helpful when navigating through associations that may return +nil+. # # === Examples # - # nil.try(:name) # => nil + # nill.try(:name) # => nil # - # Without try - # @person && @person.children.first && @person.children.first.name + # Without +try+ + # @person && !@person.children.blank? && @person.children.first.name # - # With try + # With +try+ # @person.try(:children).try(:first).try(:name) def try(*args) nil -- cgit v1.2.3 From 51f5209dc13afd8399a7f8e7a15041e642d3775b Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Mon, 18 Apr 2011 09:34:51 -0300 Subject: oops fixed typo --- activesupport/lib/active_support/core_ext/object/try.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb index c2a3abbc7c..aedf5c8c82 100644 --- a/activesupport/lib/active_support/core_ext/object/try.rb +++ b/activesupport/lib/active_support/core_ext/object/try.rb @@ -40,7 +40,7 @@ class NilClass # # === Examples # - # nill.try(:name) # => nil + # nil.try(:name) # => nil # # Without +try+ # @person && !@person.children.blank? && @person.children.first.name -- cgit v1.2.3 From 280a8709923d2bf707ec4d82ac1e5cb14941da3d Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Mon, 18 Apr 2011 10:02:55 -0300 Subject: Formated docs --- .../lib/active_support/core_ext/object/blank.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index b92277f427..6d14a6dce1 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -1,6 +1,6 @@ class Object - # An object is blank if it's false, empty, or a whitespace string. - # For example, "", " ", +nil+, [], and {} are blank. + # An object is +blank+ if it's false, empty, or a whitespace string. + # For example, "", " ", +nil+, [], and {} are +blank+. # # This simplifies: # @@ -18,7 +18,7 @@ class Object !blank? end - # Returns object if it's #present? otherwise returns nil. + # Returns object if it's present? otherwise returns nil. # object.presence is equivalent to object.present? ? object : nil. # # This is handy for any representation of objects where blank is the same @@ -38,7 +38,7 @@ class Object end class NilClass - # Instances of NilClass are always blank + # Instances of +NilClass+ are always +blank+. # # === Example # @@ -49,7 +49,7 @@ class NilClass end class FalseClass - # Instances of FalseClass are always blank + # Instances of +FalseClass+ are always +blank+. # # === Example # @@ -60,7 +60,7 @@ class FalseClass end class TrueClass - # Instances of TrueClass are never blank + # Instances of +TrueClass+ are never +blank+. # # === Example # @@ -71,7 +71,7 @@ class TrueClass end class Array - # An array is blank if it's empty + # An array is +blank+ if it's +empty+. # # === Examples # @@ -81,7 +81,7 @@ class Array end class Hash - # A hash is blank if it's empty + # A hash is +blank+ if it's +empty+. # # === Examples # @@ -91,7 +91,7 @@ class Hash end class String - # A string is blank if it's empty or contains whitespaces only + # A string is +blank+ if it's empty or contains whitespaces only. # # === Examples # -- cgit v1.2.3 From 571b4a2a91fcfb46166349c148326d38999a0d7d Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 19 Apr 2011 20:51:24 +0200 Subject: Revert "Formated docs" Reason: "To be blank" and "to be empty" belongs to our everyday terminology, they go in regular font. This reverts commit 280a8709923d2bf707ec4d82ac1e5cb14941da3d. --- .../lib/active_support/core_ext/object/blank.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index 6d14a6dce1..b92277f427 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -1,6 +1,6 @@ class Object - # An object is +blank+ if it's false, empty, or a whitespace string. - # For example, "", " ", +nil+, [], and {} are +blank+. + # An object is blank if it's false, empty, or a whitespace string. + # For example, "", " ", +nil+, [], and {} are blank. # # This simplifies: # @@ -18,7 +18,7 @@ class Object !blank? end - # Returns object if it's present? otherwise returns nil. + # Returns object if it's #present? otherwise returns nil. # object.presence is equivalent to object.present? ? object : nil. # # This is handy for any representation of objects where blank is the same @@ -38,7 +38,7 @@ class Object end class NilClass - # Instances of +NilClass+ are always +blank+. + # Instances of NilClass are always blank # # === Example # @@ -49,7 +49,7 @@ class NilClass end class FalseClass - # Instances of +FalseClass+ are always +blank+. + # Instances of FalseClass are always blank # # === Example # @@ -60,7 +60,7 @@ class FalseClass end class TrueClass - # Instances of +TrueClass+ are never +blank+. + # Instances of TrueClass are never blank # # === Example # @@ -71,7 +71,7 @@ class TrueClass end class Array - # An array is +blank+ if it's +empty+. + # An array is blank if it's empty # # === Examples # @@ -81,7 +81,7 @@ class Array end class Hash - # A hash is +blank+ if it's +empty+. + # A hash is blank if it's empty # # === Examples # @@ -91,7 +91,7 @@ class Hash end class String - # A string is +blank+ if it's empty or contains whitespaces only. + # A string is blank if it's empty or contains whitespaces only # # === Examples # -- cgit v1.2.3 From eaf0d1a491c836ec3c05417613272df423c83bb5 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 19 Apr 2011 20:58:00 +0200 Subject: commit copy-edit: simplifies blank? rdoc and revises formatting --- .../lib/active_support/core_ext/object/blank.rb | 47 +++++++++++----------- 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index b92277f427..20085c4fb3 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -18,8 +18,8 @@ class Object !blank? end - # Returns object if it's #present? otherwise returns nil. - # object.presence is equivalent to object.present? ? object : nil. + # Returns object if it's present? otherwise returns +nil+. + # object.presence is equivalent to object.present? ? object : nil. # # This is handy for any representation of objects where blank is the same # as not present at all. For example, this simplifies a common check for @@ -38,72 +38,71 @@ class Object end class NilClass - # Instances of NilClass are always blank + # +nil+ is blank: # - # === Example + # nil.blank? # => true # - # nil.blank? # => true def blank? true end end class FalseClass - # Instances of FalseClass are always blank + # +false+ is blank: # - # === Example + # false.blank? # => true # - # false.blank? # => true def blank? true end end class TrueClass - # Instances of TrueClass are never blank + # +true+ is not blank: # - # === Example + # true.blank? # => false # - # true.blank? # => false def blank? false end end class Array - # An array is blank if it's empty + # An array is blank if it's empty: # - # === Examples + # [].blank? # => true + # [1,2,3].blank? # => false # - # [].blank? # => true - # [1,2,3].blank? # => false alias_method :blank?, :empty? end class Hash - # A hash is blank if it's empty + # A hash is blank if it's empty: # - # === Examples + # {}.blank? # => true + # {:key => 'value'}.blank? # => false # - # {}.blank? # => true - # {:key => 'value'}.blank? # => false alias_method :blank?, :empty? end class String - # A string is blank if it's empty or contains whitespaces only + # A string is blank if it's empty or contains whitespaces only: # - # === Examples + # "".blank? # => true + # " ".blank? # => true + # " something here ".blank? # => false # - # "".blank? # => true - # " ".blank? # => true - # " something here ".blank? # => false def blank? self !~ /\S/ end end class Numeric #:nodoc: + # No number is blank: + # + # 1.blank? # => false + # 0.blank? # => false + # def blank? false end -- cgit v1.2.3 From 5fee98adf8ce515a98ddd7d7833ab9d730489bad Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 19 Apr 2011 21:15:15 +0200 Subject: remove unwanted Example headers as per the guidelines, s/instaces of NilClass/nil/ and friends, completes some rdocs --- .../active_support/core_ext/object/duplicable.rb | 57 ++++++++++++++-------- 1 file changed, 36 insertions(+), 21 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/duplicable.rb b/activesupport/lib/active_support/core_ext/object/duplicable.rb index 0f9129d0b6..02cb5dfee7 100644 --- a/activesupport/lib/active_support/core_ext/object/duplicable.rb +++ b/activesupport/lib/active_support/core_ext/object/duplicable.rb @@ -15,74 +15,89 @@ # That's why we hardcode the following cases and check duplicable? instead of # using that rescue idiom. class Object - # Can you safely .dup this object? - # False for nil, false, true, symbols, numbers, class and module objects; true otherwise. + # Can you safely dup this object? + # + # False for +nil+, +false+, +true+, symbols, numbers, class and module objects; + # true otherwise. def duplicable? true end end class NilClass - # Instances of NilClass are not duplicable + # +nil+ is not duplicable: # - # === Example + # nil.duplicable? # => false + # nil.dup # => TypeError: can't dup NilClass # - # nil.duplicable? # => false - # nil.dup # => TypeError: can't dup NilClass def duplicable? false end end class FalseClass - # Instances of FalseClass are not duplicable + # +false+ is not duplicable: # - # === Example + # false.duplicable? # => false + # false.dup # => TypeError: can't dup FalseClass # - # false.duplicable? # => false - # false.dup # => TypeError: can't dup FalseClass def duplicable? false end end class TrueClass - # Instances of TrueClass are not duplicable + # +true+ is not duplicable: # - # === Example + # true.duplicable? # => false + # true.dup # => TypeError: can't dup TrueClass # - # true.duplicable? # => false - # true.dup # => TypeError: can't dup TrueClass def duplicable? false end end class Symbol - # Symbols are not duplicable + # Symbols are not duplicable: # - # === Example + # :my_symbol.duplicable? # => false + # :my_symbol.dup # => TypeError: can't dup Symbol # - # :my_symbol.duplicable? # => false - # :my_symbol.dup # => TypeError: can't dup Symbol def duplicable? false end end -class Numeric #:nodoc: +class Numeric + # Numbers are not duplicable: + # + # 3.duplicable? # => false + # 3.dup # => TypeError: can't dup Fixnum + # def duplicable? false end end -class Class #:nodoc: +class Class + # Classes are not duplicable: + # + # c = Class.new # => # + # c.dup # => # + # + # Note +dup+ returned the same class object. def duplicable? false end end -class Module #:nodoc: +class Module + # Modules are not duplicable: + # + # m = Module.new # => # + # m.dup # => # + # + # Note +dup+ returned the same module object. def duplicable? false end -- cgit v1.2.3