diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-20 08:52:48 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-20 08:52:48 +0100 |
commit | 206c5643aae40b0884d42fdb8caeb3f763936fa9 (patch) | |
tree | 608f5cc7daab7b58b3d159429c595303e7e1c7d4 /activesupport/lib | |
parent | fb1eebac940d0648d1640d20a24f085d901d6f30 (diff) | |
parent | 20a346170cf3922d16e265487cfb1abcc85383c1 (diff) | |
download | rails-206c5643aae40b0884d42fdb8caeb3f763936fa9.tar.gz rails-206c5643aae40b0884d42fdb8caeb3f763936fa9.tar.bz2 rails-206c5643aae40b0884d42fdb8caeb3f763936fa9.zip |
Merge branch 'master' of git@github.com:rails/rails
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 |