2008-06-04 16:02:51 -04:00
|
|
|
module ActiveSupport
|
2008-09-03 12:58:47 -04:00
|
|
|
# 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:
|
|
|
|
#
|
2012-09-17 01:22:18 -04:00
|
|
|
# Rails.env == 'production'
|
2008-09-03 12:58:47 -04:00
|
|
|
#
|
|
|
|
# you can call this:
|
|
|
|
#
|
|
|
|
# Rails.env.production?
|
2008-06-04 16:06:32 -04:00
|
|
|
class StringInquirer < String
|
2012-08-05 15:30:01 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def respond_to_missing?(method_name, include_private = false)
|
|
|
|
method_name[-1] == '?'
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(method_name, *arguments)
|
|
|
|
if method_name[-1] == '?'
|
|
|
|
self == method_name[0..-2]
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
2008-06-04 16:02:51 -04:00
|
|
|
end
|
2008-06-03 18:44:56 -04:00
|
|
|
end
|
2008-06-04 16:02:51 -04:00
|
|
|
end
|