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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:23:50+00:00 2026-06-15T22:23:50+00:00

I am writing a Ruby hash to a file using YAML. File.open(output_file, w) {|file|

  • 0

I am writing a Ruby hash to a file using YAML.

File.open(output_file, "w") {|file| file.puts YAML::dump(final)}

The hash contains strings as keys and floats as values.

When my strings contain only letter they are outputted as such in the file file:

abc: 1.0
bcd: 1.0
cde: 1.0

When a string starts with a space it is outputted as such:

! ' ab': 1.0

When I read the file back in again everything is ok, but I want to know why this is happening and what does it mean.

I searched the YAML documentation and it says that a single exclamation point is used to represent local datatypes.

Why does this happen on string starting with spaces?

  • 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-15T22:23:51+00:00Added an answer on June 15, 2026 at 10:23 pm

    The ! is known as the “non-specific tag”. It forces the YAML engine to decode the following item as either a string, a hash, or an array. It basically disables interpreting it as a different type. I’m not sure why the engine is tagging them this way; it doesn’t seem to be needed. Perhaps it is just overzealously attempting to remove ambiguity?

    Edit: either way, it’s unneeded syntax:

    YAML.dump({' a'=>0})
    => "---\n! ' a': 0\n"
    YAML.load("---\n! ' a': 0\n") # with the bang
    => {" a"=>0}
    YAML.load("---\n' a': 0\n")   # without the bang
    => {" a"=>0}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an Ruby on Rails app using a legacy database. The problem I'm
I'm writing a Ruby C Extension where I'm using math.h . It's being compiled
I'm writing some ruby code that goes to the value of a hash of
I'm writing a ruby on rails application using mongoid and I'm wondering about the
I'm writing a Ruby gem using the {key: 'value'} syntax for hashes throughout my
I'm re-writing a Rails web app in C#. I'm really stuck with Ruby's hash
I'm writing an application that convert data serialized in ruby (file A) to xml
Is there a nice (one line) way of writing a hash in ruby with
I'm writing a ruby program that uses floats. I'm having trouble with the precision.
I am writing a Ruby script to generate a CSV file. My understanding is

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.