Skip to content

Instantly share code, notes, and snippets.

@ingeniarius
Created February 24, 2012 19:56
Show Gist options
  • Save ingeniarius/1903315 to your computer and use it in GitHub Desktop.
Save ingeniarius/1903315 to your computer and use it in GitHub Desktop.
Creation of inquirer methods on the fly for performance boost
module ActiveSupport
module StringInquirerPatch
def self.included klass
klass.send :remove_method, :method_missing
end
def method_missing method_name, *arguments
if method_name.to_s[-1,1] == "?"
is_eql_to_self = (self == method_name.to_s[0..-2])
define_singleton_method(method_name) { is_eql_to_self }
is_eql_to_self
else
super
end
end
end
end
ActiveSupport::StringInquirer.send :include, ActiveSupport::StringInquirerPatch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment