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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:19:45+00:00 2026-06-03T22:19:45+00:00

I need to join output of a hash into a string. The hash looks

  • 0

I need to join output of a hash into a string.

The hash looks like this:

 nas.location.walledgardens.to_s

  => "[#<Walledgarden id: 1, location_id: 12, url: \"polka.com\", created_at: \"2012-05-14 17:02:47\", updated_at: \"2012-05-14 17:02:47\">, #<Walledgarden id: 2, location_id: 12, url: \"test.com\", created_at: \"2012-05-14 17:02:47\", updated_at: \"2012-05-14 17:02:47\">, #<Walledgarden id: 3, location_id: 12, url: \"help.com\", created_at: \"2012-05-14 17:02:47\", updated_at: \"2012-05-14 17:02:47\">, #<Walledgarden id: 4, location_id: 12, url: \"yell.com\", created_at: \"2012-05-14 17:02:47\", updated_at: \"2012-05-14 17:02:47\">, #<Walledgarden id: 5, location_id: 12, url: \"sausage.com\", created_at: \"2012-05-14 17:02:47\", updated_at: \"2012-05-14 17:02:47\">]" 

I need to join the url values into the following format:

polka.com,test.com,help.com

What the best way to do this? I can easily look through it but the output has line breaks and I need these removed plus the commas.

  • 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-03T22:19:46+00:00Added an answer on June 3, 2026 at 10:19 pm
    nas.location.walledgardens.collect { |w| w.url }.join(",")
    

    The .collect method will collect all what that block returns and put it in an array, and then the join puts that array in a string, separated by whatever you give it (so a comma).

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

Sidebar

Related Questions

I've got a bunch of .coffee files that I need to join into one
I need to convert a string of numbers into a string of letters to
I need to join this mySQL table: TABLE1 id pagetitle 1 remodeling 2 handywork
I have this problem. I'm creating an editor and I need console output(sys.stderr and
given the first table ,i need to join this table with the same table
Need to INNER JOIN a resultset returned by UPDATE OUTPUT with another table and
In short, my naive code (in Ruby) looks like: # $seen is a hash
I need to join two tables from different MySQL (PHP) connection strings and different
I need to join two JPA entities on a property when there is no
I have 3 tables I need to join. The contracts table is the main

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.