Skip to content

Commit aca9e2f

Browse files
rtlongdefunkt
authored andcommitted
Fix Resque::Helpers#constantize to work correctly on 1.9.2
1 parent c8a3e0a commit aca9e2f

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

lib/resque/helpers.rb

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,23 @@ def classify(dashed_word)
4040
dashed_word.split('-').each { |part| part[0] = part[0].chr.upcase }.join
4141
end
4242

43-
# Given a camel cased word, returns the constant it represents
43+
# Tries to find a constant with the name specified in the argument string:
4444
#
45-
# constantize('JobName') # => JobName
45+
# constantize("Module") # => Module
46+
# constantize("Test::Unit") # => Test::Unit
47+
#
48+
# The name is assumed to be the one of a top-level constant, no matter
49+
# whether it starts with "::" or not. No lexical context is taken into
50+
# account:
51+
#
52+
# C = 'outside'
53+
# module M
54+
# C = 'inside'
55+
# C # => 'inside'
56+
# constantize("C") # => 'outside', same as ::C
57+
# end
58+
#
59+
# NameError is raised when the constant is unknown.
4660
def constantize(camel_cased_word)
4761
camel_cased_word = camel_cased_word.to_s
4862

@@ -55,7 +69,13 @@ def constantize(camel_cased_word)
5569

5670
constant = Object
5771
names.each do |name|
58-
constant = constant.const_get(name) || constant.const_missing(name)
72+
args = Module.method(:const_get).arity != 1 ? [false] : []
73+
74+
if constant.const_defined?(name, *args)
75+
constant = constant.const_get(name)
76+
else
77+
constant = constant.const_missing(name)
78+
end
5979
end
6080
constant
6181
end

0 commit comments

Comments
 (0)