rails/rails — pull request #16628 by citizen428 (2014-08-22 05:03:03+00:00)
Title: Add ActiveSupport::Inflector.constantize_only

This works like `ActiveSupport::Inflector.constantize, but additionally checks the constant against a provided whitelist, which is useful for constantizing user input, e.g. from params.

```ruby
'Module'.constantize_only('Module') #=> Module
'Test::Unit'.constantize_only('Test::Unit') #=> Test::Unit
```
Internally this uses `safe_constantize`, so `nil` is returned when the name is not in CamelCase or the constant (or part of it) is unknown. `NameError` is raised when the name is not whitelisted.