diff options
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
6 files changed, 26 insertions, 19 deletions
diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index ca9b2c1b60..45bec264ff 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -110,12 +110,6 @@ class Class private def singleton_class? - # in case somebody is crazy enough to overwrite allocate - allocate = Class.instance_method(:allocate) - # object.class always points to a real (non-singleton) class - allocate.bind(self).call.class != self - rescue TypeError - # MRI/YARV/JRuby all disallow creating new instances of a singleton class - true + !name || '' == name end end diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index 3e05c6eaf2..ddb4f3012f 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -20,6 +20,7 @@ module Enumerable # "2006-02-24 -> Transcript, Transcript" # "2006-02-23 -> Transcript" def group_by + return to_enum :group_by unless block_given? assoc = ActiveSupport::OrderedHash.new each do |element| @@ -75,9 +76,10 @@ module Enumerable # # (1..5).each_with_object(1) { |value, memo| memo *= value } # => 1 # - def each_with_object(memo, &block) + def each_with_object(memo) + return to_enum :each_with_object, memo unless block_given? each do |element| - block.call(element, memo) + yield element, memo end memo end unless [].respond_to?(:each_with_object) @@ -90,14 +92,22 @@ module Enumerable # => { "Chade- Fowlersburg-e" => <Person ...>, "David Heinemeier Hansson" => <Person ...>, ...} # def index_by + return to_enum :index_by unless block_given? Hash[map { |elem| [yield(elem), elem] }] end - # Returns true if the collection has more than 1 element. Functionally equivalent to collection.size > 1. + # Returns true if the enumerable has more than 1 element. Functionally equivalent to enum.to_a.size > 1. # Can be called with a block too, much like any?, so people.many? { |p| p.age > 26 } returns true if more than 1 person is over 26. - def many?(&block) - size = block_given? ? count(&block) : self.size - size > 1 + def many? + cnt = 0 + if block_given? + any? do |element| + cnt += 1 if yield element + cnt > 1 + end + else + any?{ (cnt += 1) > 1 } + end end # The negative of the Enumerable#include?. Returns true if the collection does not include the object. diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index 1777a4b32d..41f9a76b13 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -127,10 +127,6 @@ class Module end module_eval(<<-EOS, file, line - 5) - if instance_methods(false).map(&:to_s).include?("#{prefix}#{method}") - remove_possible_method("#{prefix}#{method}") - end - def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block) #{to}.__send__(#{method.inspect}, *args, &block) # client.__send__(:name, *args, &block) rescue NoMethodError # rescue NoMethodError diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index d060ac04d8..fe27f45295 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -1,4 +1,5 @@ # encoding: utf-8 +require 'active_support/core_ext/string/encoding' class Object # An object is blank if it's false, empty, or a whitespace string. @@ -99,7 +100,12 @@ class String # " something here ".blank? # => false # def blank? - self !~ NON_WHITESPACE_REGEXP + # 1.8 does not takes [:space:] properly + if encoding_aware? + self !~ /[^[:space:]]/ + else + self !~ NON_WHITESPACE_REGEXP + end end end diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 664537eea4..0f8933b658 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 require 'date' require 'active_support/core_ext/time/publicize_conversion_methods' require 'active_support/core_ext/time/calculations' diff --git a/activesupport/lib/active_support/core_ext/string/multibyte.rb b/activesupport/lib/active_support/core_ext/string/multibyte.rb index 41de4d6435..aae1cfccf2 100644 --- a/activesupport/lib/active_support/core_ext/string/multibyte.rb +++ b/activesupport/lib/active_support/core_ext/string/multibyte.rb @@ -35,7 +35,7 @@ class String # object. Interoperability problems can be resolved easily with a +to_s+ call. # # For more information about the methods defined on the Chars proxy see ActiveSupport::Multibyte::Chars. For - # information about how to change the default Multibyte behaviour see ActiveSupport::Multibyte. + # information about how to change the default Multibyte behavior see ActiveSupport::Multibyte. def mb_chars if ActiveSupport::Multibyte.proxy_class.consumes?(self) ActiveSupport::Multibyte.proxy_class.new(self) |