在以下代码中我遇到了一个错误,指出syntax error, unexpected '\n', expecting :: or '[' or '.' (SyntaxError)
但我不知道问题出在哪里。
module Xaaron
class ApiKey.class_eval # It does not like this....
include Promiscuous::Publisher
publish :xaaron_users_id, :api_key, :as => :ApiKey
end
end
我使用class_eval
错了吗?
答案 0 :(得分:2)
您可以删除class
关键字,并在调用class_eval
后添加do
(传递一个区块):
module Xaaron
ApiKey.class_eval do
include Promiscuous::Publisher
publish :xaaron_users_id, :api_key, :as => :ApiKey
end
end
(鉴于ApiKey
已存在)
或者您可以完全删除class_eval
:
module Xaaron
class ApiKey
include Promiscuous::Publisher
publish :xaaron_users_id, :api_key, :as => :ApiKey
end
end
即使ApiKey
已经存在,这也会有用......这就是红宝石的工作原理......