This method is deprecated or moved on the latest stable version.
The last existing version (v2.3.8) is shown here.
class_collisions(*class_names)
public
Check whether the given class names are already taken by Ruby or Rails. In the future, expand to check other
namespaces such as the rest of the user’s app.
# File railties/lib/rails_generator/commands.rb, line 173
def class_collisions(*class_names)
path = class_names.shift
class_names.flatten.each do |class_name|
# Convert to string to allow symbol arguments.
class_name = class_name.to_s
# Skip empty strings.
next if class_name.strip.empty?
# Split the class from its module nesting.
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, *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, *extra)
raise_class_collision(class_name)
end
end
end