简体   繁体   English

从Rails引擎在主应用程序中添加常量数组

[英]Appending a constant Array in the main app from a Rails engine

yes, I want to append a CONSTANT, 是的,我想添加一个常量,

I have an array that is stored as a constant in the mainapp, something like 我有一个数组作为常量存储在mainapp中,类似

class FOO
  ABILITY = [["xxxx","XX"],["yy","YYY"]]
end

above constant is used throughout the mainapp in various ways. 上面的常量以各种方式在mainapp中使用。

now, I have a rails engine that extends the mainapps abilities, and would like to extend the ABILITY array in the main app so if I where to do a 现在,我有一个可扩展mainapps功能的rails引擎,并且想扩展main app中的ABILITY数组,所以如果我在哪里做

ABILITY.each

i would get an extra pair. 我会多买一对。

Without thinking, I just did a 没想到,我只是做了一个

class BAR
  FOO::ABILITY << ["zzzz","ZZZZ"]
end

of course this didn't do anything. 当然,这什么也没做。

I have never considered appending a constant, which in its self seems like a bad thing to do, but considering the purpose of the RailsEngine, for it feels like an adequate idea, thanks in advance. 我从未考虑过添加一个常量,这本身并不是一件好事,但是考虑到RailsEngine的用途,因为它是一个适当的主意,请事先感谢。

class FOO
  ABILITY = [["xxx","XX"],["yy","yyyy"]]
end

class BAR
  T= FOO::ABILITY << ["zzz","ZZ"]
end

BAR::T
=> [["xxx", "XX"], ["yy", "yyyy"], ["zzz", "ZZ"]]

you were missing a "," in your ABILITY array. 您在ABILITY数组中丢失了“,”。 Does that help? 有帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM