From 70d535bbfb4c7e5a033b12a979d26167f30465d0 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Wed, 15 Apr 2015 12:56:43 +0200 Subject: [PATCH] Replace regular expressions with string manipulations --- lib/twitter/factory.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/twitter/factory.rb b/lib/twitter/factory.rb index de9d17914..83ff094f0 100644 --- a/lib/twitter/factory.rb +++ b/lib/twitter/factory.rb @@ -10,7 +10,7 @@ class << self # @return [Twitter::Base] def new(method, klass, attrs = {}) type = attrs.fetch(method.to_sym) - const_name = type.gsub(/\/(.?)/) { "::#{Regexp.last_match[1].upcase}" }.gsub(/(?:^|_)(.)/) { Regexp.last_match[1].upcase } + const_name = type.split('_').collect(&:capitalize).join klass.const_get(const_name.to_sym).new(attrs) end end