aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-09-23 16:49:05 +0200
committerJosé Valim <jose.valim@gmail.com>2011-09-23 16:49:05 +0200
commit36699977f2ddbb937aac97998d2d8503499c57e0 (patch)
tree84d48908edca73755dc13b31bd861e661db83ede /activesupport
parente8987c30d0dc3ae5903a6d3a6e293641759b6fc4 (diff)
downloadrails-36699977f2ddbb937aac97998d2d8503499c57e0.tar.gz
rails-36699977f2ddbb937aac97998d2d8503499c57e0.tar.bz2
rails-36699977f2ddbb937aac97998d2d8503499c57e0.zip
Update CHANGELOG for safe_constantize.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb5
2 files changed, 6 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 537980d6a1..63f406cd9f 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*Rails 3.2.0 (unreleased)*
+* Added safe_constantize that constantizes a string but returns nil instead of an exception if the constant (or part of it) does not exist [Ryan Oblak]
+
* ActiveSupport::OrderedHash is now marked as extractable when using Array#extract_options! [Prem Sichanugrist]
* Added Array#prepend as an alias for Array#unshift and Array#append as an alias for Array#<< [DHH]
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index dd232a5e2f..934529d496 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -239,10 +239,13 @@ module ActiveSupport
# "C".safe_constantize # => 'outside', same as ::C
# end
#
- # nil is returned when the name is not in CamelCase or the constant is
+ # nil is returned when the name is not in CamelCase or the constant (or part of it) is
# unknown.
#
# "blargle".safe_constantize # => nil
+ # "UnknownModule".safe_constantize # => nil
+ # "UnknownModule::Foo::Bar".safe_constantize # => nil
+ #
def safe_constantize(camel_cased_word)
begin
constantize(camel_cased_word)