4
我有需要初始化一个类,但它的命名空间是这样的:调用使用Rails constantize偏转一个命名空间类
SomeThing::MyClass.new()
但我从一耙的任务ARGS调用它,所以它涉及作为一个字符串:
task :blah, [:my_class_name] => :environment do |t, args|
class_name = args[:my_class_name].camelize.constantize
puts class_name
end
所以,很显然,如果我叫耙任务是这样的:
rake blah[my_class]
我的任务回报:
MyClass # <= Actual ruby object
但是我怎样才能得到它从之前的另一种方法链接命名空间中运行,就像这样:
SomeThing::MyClass.new()
从作为输入提供的字符串?