aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2015-01-03 14:58:17 +0000
committerVijay Dev <vijaydev.cse@gmail.com>2015-01-03 14:58:17 +0000
commit4b9dba99d65b1bd27576b16a68d7d18522bae9ea (patch)
tree4672dd2377a4e4ef71992c5478f2606f5d86e371 /activesupport/lib/active_support
parent02e72a49d1c99084fef2c78c3a194e03b879099d (diff)
parent7cc145ec65167084e8b05d9462eaf94534fa0168 (diff)
downloadrails-4b9dba99d65b1bd27576b16a68d7d18522bae9ea.tar.gz
rails-4b9dba99d65b1bd27576b16a68d7d18522bae9ea.tar.bz2
rails-4b9dba99d65b1bd27576b16a68d7d18522bae9ea.zip
Merge branch 'master' of github.com:rails/docrails
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/name_error.rb14
-rw-r--r--activesupport/lib/active_support/core_ext/object/try.rb12
2 files changed, 23 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/name_error.rb b/activesupport/lib/active_support/core_ext/name_error.rb
index e1ebd4f91c..b82148e4e5 100644
--- a/activesupport/lib/active_support/core_ext/name_error.rb
+++ b/activesupport/lib/active_support/core_ext/name_error.rb
@@ -1,5 +1,12 @@
class NameError
# Extract the name of the missing constant from the exception message.
+ #
+ # begin
+ # HelloWorld
+ # rescue NameError => e
+ # e.missing_name
+ # end
+ # # => "HelloWorld"
def missing_name
if /undefined local variable or method/ !~ message
$1 if /((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/ =~ message
@@ -7,6 +14,13 @@ class NameError
end
# Was this exception raised because the given name was missing?
+ #
+ # begin
+ # HelloWorld
+ # rescue NameError => e
+ # e.missing_name?("HelloWorld")
+ # end
+ # # => true
def missing_name?(name)
if name.is_a? Symbol
last_name = (missing_name || '').split('::').last
diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb
index 26b8d58948..6b3fc48a3f 100644
--- a/activesupport/lib/active_support/core_ext/object/try.rb
+++ b/activesupport/lib/active_support/core_ext/object/try.rb
@@ -63,9 +63,12 @@ class Object
try!(*a, &b) if a.empty? || respond_to?(a.first)
end
- # Same as #try, but will raise a NoMethodError exception if the receiver is not +nil+ and
- # does not implement the tried method.
-
+ # Same as #try, but will raise a NoMethodError exception if the receiver is
+ # not +nil+ and does not implement the tried method.
+ #
+ # "a".try!(:upcase) # => "A"
+ # nil.try!(:upcase) # => nil
+ # 123.try!(:upcase) # => NoMethodError: undefined method `upcase' for 123:Fixnum
def try!(*a, &b)
if a.empty? && block_given?
if b.arity.zero?
@@ -94,6 +97,9 @@ class NilClass
nil
end
+ # Calling +try!+ on +nil+ always returns +nil+.
+ #
+ # nil.try!(:name) # => nil
def try!(*args)
nil
end