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 4251426
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:39:37+00:00 2026-05-21T04:39:37+00:00

This method is just changing the id for any player_id that is found. Reek

  • 0

This method is just changing the id for any player_id that is found. Reek hates it, but I can’t find a way to refactor it in a meaningful way.

(1..9).each { |n|
    n = n.to_s
    self.player_ids[n] = self.site_id.clone << "_" << self.player_ids[n].clone if self.player_ids[n]        
}

Do I just have to live with this duplication because the clone function doesn’t allow me to:

player_id = self.player_ids[n]
player_id = self.site_id.clone << "_" << player_id.clone if player_id

Sample input:

{:player_ids => {"2" => "player_name1", "6" => "player_name4", "9" => "player_name9"}

output:

{:player_ids => {"2" => "PRE_player_name1", "6" => "PRE_player_name4", "9" => "PRE_player_name9"}
  • 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-21T04:39:37+00:00Added an answer on May 21, 2026 at 4:39 am

    Here are two possible techniques, based on your sample input and output:

    site_id = 'PRE'
    prefix  = "#{site_id}_"
    h = {:player_ids => {"2" => "player_name1", "6" => "player_name4", "9" => "player_name9"}}
    
    # If mutating the original hash is not OK
    h2 = h.dup
    h2[:player_ids] = Hash[ h[:player_ids].map{ |s,n| [s, n.sub(/^/,prefix)] } ]
    p h, h2
    #=> {:player_ids=>{"2"=>"player_name1", "6"=>"player_name4", "9"=>"player_name9"}}
    #=> {:player_ids=>{"2"=>"PRE_player_name1", "6"=>"PRE_player_name4", "9"=>"PRE_player_name9"}}
    
    # If mutating the original hash is OK
    h[:player_ids].each{ |id_string,name| name.sub! /^/, prefix }
    p h
    #=> {:player_ids=>{"2"=>"PRE_player_name1", "6"=>"PRE_player_name4", "9"=>"PRE_player_name9"}}
    

    If this is not what you want, please edit your question’s sample input/output and post a comment clarifying your needs.

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

Sidebar

Related Questions

I was just wondering what this method does because just from the title it
I'm just to figure out what does this method do, I know there must
This simple Python method I put together just checks to see if Tomcat is
As I understand it forms is just a method to authenticate users. Is this
I was just reading this line: The first thing the format() method does is
Right now we just use something like this stopWatch.Start(); try { method(); } finally
This method that draws my tiles seems to be quite slow, Im not sure
This method is working totally right in matlab. but, when I compiled it in
Basically I want to replicate the page changing effect found here, at http://timvandamme.com/ But
I need to create an method invoker that any thread (Thread B for example

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.