codahale/bcrypt-ruby — pull request #63 by tjschuck (2013-05-03 23:54:35+00:00)
Title: Allow a default cost to be set externally

Currently, if you're using bcrypt-ruby externally (like in a Rails app), you can't re-set the default cost to match your own business concerns.

It seems like a common desire to do something like `BCrypt::Engine::DEFAULT_COST = 12` in your config/environments/production.rb for **SUPER ENTERPRISE SECURITY™**, or a lower value if you want auth requests to be a little snappier (like for an API that requires passing through a password with every request).

Re-setting the constant _works_, but causes a `"warning: already initialized constant DEFAULT_COST"`, which makes sense, because, y'know, "constant".

This fix makes `cost` a settable global attribute, allowing you to set `BCrypt::Engine.cost = some_value` externally, defaulting internally to `DEFAULT_COST`.