2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
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
|
2015-03-04 23:35:34 -05:00
|
|
|
# in a StringInquirer object, so instead of calling this:
|
2008-09-03 12:58:47 -04:00
|
|
|
#
|
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?
|
2016-08-03 02:39:55 -04:00
|
|
|
#
|
|
|
|
# == Instantiating a new StringInquirer
|
|
|
|
#
|
|
|
|
# vehicle = ActiveSupport::StringInquirer.new('car')
|
|
|
|
# vehicle.car? # => true
|
|
|
|
# vehicle.bike? # => false
|
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)
|
2017-01-14 13:36:27 -05:00
|
|
|
(method_name[-1] == "?") || super
|
2012-08-05 15:30:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(method_name, *arguments)
|
2016-08-06 11:58:50 -04:00
|
|
|
if method_name[-1] == "?"
|
2012-08-05 15:30:01 -04:00
|
|
|
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
|