Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix Resque::Helpers#constantize to work correctly on 1.9.2

  • Loading branch information...
commit aca9e2fa5abc88c478bebb59d8f173b56b6d94b0 1 parent c8a3e0a
@rtlong rtlong authored defunkt committed
Showing with 23 additions and 3 deletions.
  1. +23 −3 lib/resque/helpers.rb
View
26 lib/resque/helpers.rb
@@ -40,9 +40,23 @@ def classify(dashed_word)
dashed_word.split('-').each { |part| part[0] = part[0].chr.upcase }.join
end
- # Given a camel cased word, returns the constant it represents
+ # Tries to find a constant with the name specified in the argument string:
#
- # constantize('JobName') # => JobName
+ # constantize("Module") # => Module
+ # constantize("Test::Unit") # => Test::Unit
+ #
+ # The name is assumed to be the one of a top-level constant, no matter
+ # whether it starts with "::" or not. No lexical context is taken into
+ # account:
+ #
+ # C = 'outside'
+ # module M
+ # C = 'inside'
+ # C # => 'inside'
+ # constantize("C") # => 'outside', same as ::C
+ # end
+ #
+ # NameError is raised when the constant is unknown.
def constantize(camel_cased_word)
camel_cased_word = camel_cased_word.to_s
@@ -55,7 +69,13 @@ def constantize(camel_cased_word)
constant = Object
names.each do |name|
- constant = constant.const_get(name) || constant.const_missing(name)
+ args = Module.method(:const_get).arity != 1 ? [false] : []
+
+ if constant.const_defined?(name, *args)
+ constant = constant.const_get(name)
+ else
+ constant = constant.const_missing(name)
+ end
end
constant
end
Please sign in to comment.
Something went wrong with that request. Please try again.