Sha256: 9c810722cbc45dd33622b34b1f20cf18d1d9726ef4243629da54dc3a832ee246
Contents?: true
Size: 1.07 KB
Versions: 16
Compression:
Stored size: 1.07 KB
Contents
module ActiveRecordDescendantAttributeAccessors def self.attr_accessor_instance_variables(obj) include_ancestor_methods = false ancestors_before_active_record_base = obj.class.ancestors.take_while { |klass| klass != ActiveRecord::Base } instance_methods_of_ancestors_before_active_record_base = ancestors_before_active_record_base .map { |klass| klass.instance_methods(include_ancestor_methods) } .flatten setter_methods_of_ancestors_before_active_record_base = instance_methods_of_ancestors_before_active_record_base .select { |meth| meth.to_s.last == '=' } possible_instance_variables_from_setter_methods = setter_methods_of_ancestors_before_active_record_base .map { |meth| meth.to_s.prepend('@').chop.to_sym } obj.instance_variables & possible_instance_variables_from_setter_methods end end
Version data entries
16 entries across 16 versions & 1 rubygems