diff options
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/enumerable.rb | 9 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/misc.rb | 13 | ||||
-rw-r--r-- | activesupport/lib/active_support/version.rb | 4 |
3 files changed, 24 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index 788f3a7e9e..a7eaccfed7 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -104,4 +104,13 @@ module Enumerable size = block_given? ? select(&block).size : self.size size > 1 end + + # Returns true if none of the elements match the given block. + # + # success = responses.none? {|r| r.status / 100 == 5 } + # + # This is a builtin method in Ruby 1.8.7 and later. + def none?(&block) + !any?(&block) + end unless [].respond_to?(:none?) end diff --git a/activesupport/lib/active_support/core_ext/object/misc.rb b/activesupport/lib/active_support/core_ext/object/misc.rb index cd0a04d32a..50f824c358 100644 --- a/activesupport/lib/active_support/core_ext/object/misc.rb +++ b/activesupport/lib/active_support/core_ext/object/misc.rb @@ -71,4 +71,17 @@ class Object def acts_like?(duck) respond_to? "acts_like_#{duck}?" end + + # Tries to send the method only if object responds to it. Return +nil+ otherwise. + # + # ==== Example : + # + # # Without try + # @person ? @person.name : nil + # + # With try + # @person.try(:name) + def try(method) + send(method) if respond_to?(method, true) + end end diff --git a/activesupport/lib/active_support/version.rb b/activesupport/lib/active_support/version.rb index 6631f233f1..3e2b29b327 100644 --- a/activesupport/lib/active_support/version.rb +++ b/activesupport/lib/active_support/version.rb @@ -1,8 +1,8 @@ module ActiveSupport module VERSION #:nodoc: MAJOR = 2 - MINOR = 2 - TINY = 1 + MINOR = 3 + TINY = 0 STRING = [MAJOR, MINOR, TINY].join('.') end |