Skip to content

Commit

Permalink
Ruby 1.9 compat: limit const_defined?
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy committed Feb 27, 2009
1 parent f732c16 commit eb217b2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions railties/lib/rails_generator/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,19 @@ def class_collisions(*class_names)
nesting = class_name.split('::')
name = nesting.pop

# Hack to limit const_defined? to non-inherited on 1.9.
extra = []
extra << false unless Object.method(:const_defined?).arity == 1

# Extract the last Module in the nesting.
last = nesting.inject(Object) { |last, nest|
break unless last.const_defined?(nest)
break unless last.const_defined?(nest, *extra)
last.const_get(nest)
}

# If the last Module exists, check whether the given
# class exists and raise a collision if so.
if last and last.const_defined?(name.camelize)
if last and last.const_defined?(name.camelize, *extra)
raise_class_collision(class_name)
end
end
Expand Down

0 comments on commit eb217b2

Please sign in to comment.