回答
相当多的修补我的恐怕。这种方法已被class_attribute
取代,但它的工作原理略有不同。以前它是足够使用write_inheritable_attribute
创建新类PARAM,现在你需要首先声明,然后赋值。
在线路17它正在使用“write_inheritable_attribute`来设置这些值。现在应该读
class_attribute :"acts_enumerated_#{key}" unless respond_to? "acts_enumerated_#{key}"
self.send(:"acts_enumerated_#{key}=", options[key])
然后,到处被使用read_inheritable_attribute(:attribute_name)
只是使用self.attribute_name
。
与此唯一的问题是,“如果属性未设置及以上方法将抛出一个错误read_inheritable_attribute`返回零。你会发现,所有的读取方法有默认值,如(56行):
read_inheritable_attribute(:acts_enumerated_on_lookup_failure) || :enforce_strict_literals
您将需要寻找所有的这些默认值和行为内实施所列举的方法:
def acts_as_enumerated(options = {})
valid_keys = [:conditions, :order, :on_lookup_failure]
default_options = {<all the default values from the code>}
options = default_options.merge options
options.assert_valid_keys(*valid_keys)
valid_keys.each do |key|
write_inheritable_attribute("acts_enumerated_#{key.to_s}".to_sym, options[key]) if options.has_key? key
end
然而这不是一个完美的设计。我可能会在append_features方法中定义class_attribute enumerated_options
,将所有选项作为散列使用,而不是为每个选项创建class_attribute。这绝对取决于你。
另外请注意,这个宝石已被写入4年前,这种方法可能不是唯一被弃用的。我不完全知道这是什么宝石是应该做的,但它可能是更容易实现,而你需要什么,而不是使用它。
将gem的回购本地克隆,并在您的rails项目中用作本地宝石的路径。因此,指定您gemfile:
gem :enumerations_mixin, :path => '/local/path/to/gem'
当你将宝石修补,叉它github,更换宝石产地在/local/path/to/gem/.git/config,把你的改变你的叉子,并替换该行于你的gemfile到follownig:
gem :enumerations_mixin, :github => 'your_acoount/enumerations_mixin'
问题的pull-request创业板的根回购,当要求无线会被接受,取代线在你的gemfile到follownig:
gem :enumerations_mixin, :github => 'protocool/enumerations_mixin'
当创业板将陆续公布线路可更换:
gem :enumerations_mixin, '~> <new_verison>'
kk ...改写问题:如何替换read_inheritable_attribute的使用情况?我真的不明白它的意义。 –
- 1. 修补红宝石
- 2. 猴子修补红宝石的方法
- 3. 红宝石猴子修补陷阱
- 4. 修改Rails宝石
- 5. 修改friendly_id宝石
- 6. 猴子修补包含在Ruby宝石中的Mongoid模型
- 7. Ruby on Rails Monkey修补宝石的模型
- 8. 我如何猴子修补在Bundler管理的宝石?
- 9. 猴子修补块的一个模块中的红宝石
- 10. 分离红宝石宝石中的猴子补丁?
- 11. 红宝石没有检测到宝石
- 12. Rails的猴子补丁宝石问题
- 13. 红宝石:智能补丁/更新
- 14. 如何修改Ruby宝石
- 15. 如何修改宝石?
- 16. 如何修改红宝石
- 17. 红宝石修改对象
- 18. 修改自己,红宝石
- 19. 轨3.2.8红宝石1.9.3 Dreamhost上共享主机FCGI RMagic问题
- 20. 红宝石<NoMethodError>
- 21. Shell脚本>红宝石
- 22. 红宝石GSUB '<' and '>'
- 23. 找不到宝石“logstash-devutils(> = 0)红宝石”在任何宝石来源
- 24. 有没有办法修复红宝石的宝石错误?
- 25. 下载红宝石宝石修复程序?
- 26. 如何修改一个模块里面的红宝石宝石
- 27. AASM红宝石宝石:不使用<strong>AASM</strong>宝石鉴于今后的机型限制
- 28. 找不到宝石“sqlite3的(> = 0)红宝石”
- 29. 〜>在红宝石宝石依赖中意味着什么?
- 30. 找不到宝石“rubytree(〜> 0.5.2)红宝石”,而在Debian安装
我找到了一个简单的方法:http:// code。whowah.com/ruby/rubyonrails/bbclistenlive/vendor/rails/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb –
是的,这将是最简单的方法,但我从来不喜欢这种解决方案。框架的演变,我们不应该强迫它使用旧模式,因为它们被删除的原因很充分。尽管可以作为临时解决方案。 – BroiSatse