What\'s the shortest, one-liner way to list all methods defined with attr_accessor? I would like to make it so, if I have a class MyBaseClass, any
attr_accessor
MyBaseClass
Extract the attributes in to an array, assign them to a constant, then splat them in to attr_accessor.
class SubClass < MyBaseClass ATTRS = [:id, :title, :body] attr_accessor(*ATTRS) end
Now you can access them via the constant:
puts SubClass.ATTRS #=> [:id, :title, :body]