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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:11:26+00:00 2026-06-19T00:11:26+00:00

I wasn’t working with ruby 1.8.7 and recently I was surprised that: {:k =>

  • 0

I wasn’t working with ruby 1.8.7 and recently I was surprised that:

{:k => 30}.to_s #=> "k30"

Is there ready to use fix to convert hash to string for ruby 1.8.7 to make it look like:

{:k => 30}.to_s #=> "{:k=>30}"
  • 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-19T00:11:28+00:00Added an answer on June 19, 2026 at 12:11 am

    hash.to_s has indeed been changed from 1.8.7 to 1.9.3.

    In 1.8.7, (ref: http://ruby-doc.org/core-1.8.7/Hash.html#method-i-to_s):

    Converts hsh to a string by converting the hash to an array of [ key, value ] pairs and then converting that array to a string using Array#join with the default separator.

    In 1.9.3, (ref: http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-to_s)

    Alias for : inspect

    You could monkey-patch Hash class in 1.8.7 to do the same locally with the following:

    class Hash
      alias :to_s :inspect
    end
    

    Before monkey-patching:

    1.8.7 :001 > {:k => 30}.to_s
     => "k30" 
    1.8.7 :002 > {:k => 30}.inspect
     => "{:k=>30}"
    

    Monkey-patching & after:

    1.8.7 :003 > class Hash; alias :to_s :inspect; end
     => nil 
    1.8.7 :004 > {:k => 30}.to_s
     => "{:k=>30}" 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that there wasn't much of a choice when InterruptedIOException was introduced; it
Wasn't too sure exactly how to title this question, but here's the issue that
i wasn't able to answer my question. I need a hashing method that will
I wasn't sure how to word this exactly. But I have a model that
I wasn't sure if there was any good way of doing this. But I
I wasn't even sure how to title this right. I have a page that
So an executable file wasn't working, and I found this post ( http://hintsforums.macworld.com/showthread.php?t=126972 ):
That title wasn't very descriptive; I wasn't sure how to shorten my question... Let's
I wasn't aware of a difference, but a coworker says there is, although he
I wasn't able to find a question/answer that covers this fully hence why I

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.