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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:56:50+00:00 2026-06-16T01:56:50+00:00

I have a simple YAML array with values like this %YAML 1.1 — –

  • 0

I have a simple YAML array with values like this

%YAML 1.1
---

-
  - 'd7744c3878'
  - '80705686'
-
  - 'c349b086b1'
  - '80705686'
-
  - '516e25d139'
  - '95203563'

I try the following code to iterate on them and add them to the database.

YAML.load_file("db/tokens.yml").each_value do |yml_token|

    token = Token.find_or_create_by_token_origin(
           token_origin: yml_token[0],
           token_value: yml_token[1]) 

end

But I get a NoMethodError: undefined method each_value for #<String:0x000000059ab7f8>
error when try to run the code.

Any idea what is causing this?

UPDATE:

Using Psych.load as suggested below I also get a SyntaxError: db/gallery_tokens.yml:1: unknown type of %string
%YAML 1.1
error.

require "psych"
Psych.load("db/tokens.yml").each do |yml_token|

    token = Token.find_or_create_by_token_origin(
           token_origin: yml_token[0],
           token_value: yml_token[1]) 

end
  • 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-16T01:56:51+00:00Added an answer on June 16, 2026 at 1:56 am

    It’s likely that the declaration at the top, “%YAML 1.1”, is causing problems.

    No error:

    require "yaml"
    YAML.load("---\n\n-\n  - 'd7744c3878'\n  - '80705686'").each
    => #<Enumerator: [["d7744c3878", "80705686"]]:each>
    

    Error:

    YAML.load("%YAML 1.1\n---\n\n-\n  - 'd7744c3878'\n  - '80705686'").each
    NoMethodError: undefined method `each' for "%YAML 1.1 ---\n- - 'd7744c3878' - '80705686'":String
            from (irb):4
            from /Users/modify/.rvm/rubies/ruby-1.9.2-p180/bin/irb:17:in `<main>'
    

    Here I’m using ruby 1.9.2p180 (2011-02-18 revision 30909) [i386-darwin9.8.0]. I also note that in an unmodified environment, #each_value is available for a Hash but not an Array (@oldergod).

    It looks like Psych, which is the default YAML interepreter in later versions of Ruby, can handle the %YAML 1.1 directive:

    require "psych"
    Psych.load("%YAML 1.1\n---\n\n-\n  - 'd7744c3878'\n  - '80705686'").each
    => #<Enumerator: [["d7744c3878", "80705686"]]:each> 
    

    Possible alternatives to using Psych directly would be to switch to a later version of Ruby or to strip the %YAML 1.1 header from the file.

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

Sidebar

Related Questions

I need to have correct order of values inside Ruby array after parsing YAML
I would like to read a thin YAML file using a simple C program.
I have simple front controller plugin which contains this code: http://pastebin.com/m155c59b0 When session expire
I have simple models with generic relations from this example at the Django Project
I have a deployed GAE app, and I've noticed that I have this simple
I have simple variable $body = array( 'content' => 'content test', 'is_sanitize' => true,
I have simple WPF app with two textboxes and ReactiveUI. I try to lookup
I have simple example: function File(name) { this.name = name this.text = null }
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
I have simple class with width and height member fields which define number of

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.