If I do:
name_array = Model.column_names
name_array.delete_if {|name| ["id","created_at","updated_at"].include?(name)}
pp Model.column_names
The Model.column_names command will return an array without the id, created_at & updated_at column names. It was my presumption that the name_array would have the names deleted and not the Model.column_names array.
Rails 3.0.13
Ruby 1.9.3
See the Array documentation for
delete_if:So when you delete elements from
name_array, you are actually deleting them fromModel.column_namessince they’re pointing to the same thing.If you don’t want to do that, duplicate the array before deleting: