Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8662999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:52:24+00:00 2026-06-12T16:52:24+00:00

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

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:52:25+00:00Added an answer on June 12, 2026 at 4:52 pm

    See the Array documentation for delete_if:

    Deletes every element of self for which block evaluates to true. The array is changed instantly every time the block is called and not after the iteration is over.

    So when you delete elements from name_array, you are actually deleting them from Model.column_names since they’re pointing to the same thing.

    If you don’t want to do that, duplicate the array before deleting:

    name_array = Model.column_names.dup
    name_array.delete_if {|name| ["id","created_at","updated_at"].include?(name)}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$cars = array( array('name' => 'Toyota', price => 10000, ...), array('name' => 'Ford', price
I'm trying to isolate array name and array size from code. This example of
I have an array generated by PHP array( array( 'name'=>'node1', 'id' => '4' ),
Array ( [0] => Array ( [name] => A [id] => 1 [phone] =>
Array ( [0] => Array ( [datas] => Array ( [name] => lorem [id]
i have this JSON: var projects_array = new Array( {name:myName1, id:myid1, index:1}, {name:myName2, id:myid2,
i have an array: Array ( [47] => Array ( [name] => 3543 good
I have an array that has keys and values. For eg: Array ( [name]
Given that EVAL is Evil how do I create an Array name dynamically: I
I have trouble saving my date field into database using CakePHP. Table column name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.