cattr_accessor 位于 Rails 之外
我正在尝试使用 google_search ruby 库(代码如下),但它抱怨 'cattr_accessor
是一个未定义的方法' - 你知道为什么会这样或者我如何修复它吗?
require 'rubygems'
require 'google_search'
GoogleSearch.web :q => "pink floyd"
I'm trying to use the google_search ruby library (code follows) but it complains that 'cattr_accessor
is an undefined method' - any ideas why this might be or how I could fix it?
require 'rubygems'
require 'google_search'
GoogleSearch.web :q => "pink floyd"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
cattr_accessor
似乎是一个 Rails 扩展 ,其行为类似于attr_accessor
,但可以在类及其实例上访问。如果您想复制
cattr_accessor
方法的源代码,请查看 本文档:cattr_accessor
seems to be a Rails extension that acts likeattr_accessor
, but is accessible on both the class and its instances.If you want to copy the source of the
cattr_accessor
method, check out this documentation:您可以通过包含 Ruby Facets gem 来获得此功能。在此处引用源:
https://github.com/ rubyworks/facets/blob/master/lib/core/facets/cattr.rb
您通常不需要要求 gem 中的所有代码。您可以选择性地要求您想要的东西。不过 gem 中有很多有用的扩展。
You can get this functionality by including the Ruby Facets gem. Reference the source here:
https://github.com/rubyworks/facets/blob/master/lib/core/facets/cattr.rb
You generally don't need to require all code from the gem. You can selectively require what you want. There are quite a few useful extensions in the gem though.