我是Ruby的新手,我正在尝试使新功能正常工作。我写了以下课程:
class ::GroupItem
attributes :group_enabled,
:list_count
def group_enabled
true
end
def include_group_enabled?
Topic.group_enabled object
end
def list_count
object.list_count
end
def include_list_count?
include_group_enabled?
end
end
我运行bundle exec puma
,由于某种原因,出现以下错误:
! Unable to load application: NoMethodError: undefined method `attributes' for GroupItem:Class
Did you mean? attr_writer
bundler: failed to load command: puma (/home/user/.rbenv/versions/2.6.2/bin/puma)
NoMethodError: undefined method `attributes' for GroupItem:Class
Did you mean? attr_writer
奇怪的是,当我将第一行替换为:
::GroupItem.class_eval do # instead of class ::GroupItem
有效。问题是什么?我该怎么解决?