Skip to content

Commit

Permalink
Do not check defined?(CGI) on every call #to_query
Browse files Browse the repository at this point in the history
  • Loading branch information
printercu committed May 13, 2014
1 parent c6c1642 commit f179895
Showing 1 changed file with 1 addition and 1 deletion.
@@ -1,12 +1,12 @@
require 'active_support/core_ext/object/to_param' require 'active_support/core_ext/object/to_param'
require 'cgi'


class Object class Object
# Converts an object into a string suitable for use as a URL query string, using the given <tt>key</tt> as the # Converts an object into a string suitable for use as a URL query string, using the given <tt>key</tt> as the
# param name. # param name.
# #
# Note: This method is defined as a default implementation for all Objects for Hash#to_query to work. # Note: This method is defined as a default implementation for all Objects for Hash#to_query to work.
def to_query(key) def to_query(key)
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
"#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}" "#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
end end
end end
Expand Down

0 comments on commit f179895

Please sign in to comment.