Created
February 15, 2011 16:45
-
-
Save nebolsin/827782 to your computer and use it in GitHub Desktop.
Rails 2.3.10 ActiveSupport::StringInquirer class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ActiveSupport | |
| # Wrapping a string in this class gives you a prettier way to test | |
| # for equality. The value returned by <tt>Rails.env</tt> is wrapped | |
| # in a StringInquirer object so instead of calling this: | |
| # | |
| # Rails.env == "production" | |
| # | |
| # you can call this: | |
| # | |
| # Rails.env.production? | |
| # | |
| class StringInquirer < String | |
| def method_missing(method_name, *arguments) | |
| if method_name.to_s[-1,1] == "?" | |
| self == method_name.to_s[0..-2] | |
| else | |
| super | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment