我想编写一个子类中可用的方法,其方式与Ruby on Rails中的before filter
相同,并且可以以类似的方式使用。
以下是我期望工作的代码:
# presenter_test.rb
module Presenter
def presenting(model_name)
# do generic stuff
end
end
class ApplicationPresenter
include Presenter
end
class ArticlePresenter < ApplicationPresenter
presenting :article
end
但是当使用ruby presenter_test.rb
运行时,我收到以下错误:
presenting_test.rb:12:in `<class:ArticlePresenter>':
undefined method `presenting' for ArticlePresenter:Class (NoMethodError)
from presenting_test.rb:11:in `<main>'
答案 0 :(得分:1)
您可以使用ActiveSupport::Concern
并执行以下操作:
module Presenter
extend ActiveSupport::Concern
module ClassMethods
def presenting(model_name)
# do generic stuff
end
end
end
然后你的课程应该按预期工作。
答案 1 :(得分:1)
以poros为例:
console.log( [].copyWithin.call({length: 5, 3: 1}, 0, 3) ); // How to execute?