gpt4 book ai didi

ruby-on-rails - 如何在模块内写常量?

转载 作者:太空宇宙 更新时间:2023-11-03 17:18:15 29 4
gpt4 key购买 nike

module Test1
module Test2
def self.included(base)
# Where can I declare constant ? How ?
base.extend ClassMethods
base.class_eval do
# named scopes
end
end
end
end

class abc
include Test1::Test2
end

我在哪里可以声明常量?怎么样?

最佳答案

我不确定我是否理解 - 你是不是这个意思:

module Test1
module Test2
CONSTANT = 5
def self.included(base)
# Where can I declare constant ? How ?
base.extend ClassMethods
base.class_eval do
# named scopes
end
end

module ClassMethods
end
end
end

class A
include Test1::Test2
end

puts A::CONSTANT # => 5

关于ruby-on-rails - 如何在模块内写常量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6938997/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com