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

  • Home
  • SEARCH
  • 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 959991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:06:40+00:00 2026-05-16T01:06:40+00:00

This happens in Ruby on Rails’s View, where there is a hash for another

  • 0

This happens in Ruby on Rails’s View, where there is a hash for another partial. This hash has about 20 key/value pairs.

There is (in HAML)

- if (some_conditon)
  = render :partial => 'some_name', :locals => a_hash.merge({ :extra => true })
- else
  -# a lot more processing, including concatenating the partials and return as json
  - some_var.each do |item| 
    - result_html << (render :partial => 'some_name', :locals => a_hash )
    -# etc
  - response.content_type = "application/json"
  = result_html.to_json

So the question is, should the merge be written as merge! instead? Because it is no longer needed later, if a new hash is created, a lot of time will be spent for creating this new hash (20 items in hash). If an in-place modification is done, it can use the existing hash structure and add one item to it, which will be a lot faster?

  • 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-05-16T01:06:40+00:00Added an answer on May 16, 2026 at 1:06 am

    If you are certain that modifying the existing hash is not a problem, then you could certainly use merge!. However, I’m not sure if it will be “a lot” faster than simply using merge. copying a hash of 20 or so objects probably isn’t an extremely time consuming operation. But, if it is a concern, you could benchmark the different implementations and see how much you will gain by doing one over the other.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This happens repeatedly and is very annoying. I upload some PHP code to a
I'm wondering if anyone knows how this happens? My website is down, but every
Title is the entire question. Can someone give me a reason why this happens?
I have a multi-threaded Windows application that occasionally deadlocks. Inevitably this happens on a
Code like this often happens: l = [] while foo: # baz l.append(bar) #
I've always been told that adding an element to an array happens like this:
I am curious to do what happens when you edit a post on this
Does anyone know? And a bigger question is what happens when you encounter this
If I use mod_rewrite to control all my 301 redirects, does this happen before
i'd like to prevent bots from hacking weak password-protected accounts. (e.g. this happend to

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.