Git Product home page Git Product logo

Comments (5)

magynhard avatar magynhard commented on May 11, 2024

Hi @patrickberkeley,

thank you for your contribution.

At first I thought, that there may be a bug, but the YAML library itself has the same behaviour, so it happend not by my extending gem.

After some research I found out, that your described behaviour is indeed a part of the official YAML specification:
https://yaml.org/type/bool.html

All of the following key words are transformed into booleans:

YAML 1.1 specification

 y|Y|yes|Yes|YES|n|N|no|No|NO
|true|True|TRUE|false|False|FALSE
|on|On|ON|off|Off|OFF

YAML 1.2 specification:

true | True | TRUE | false | False | FALSE

Ruby YAML apparently implements the 1.1 specification.

If you want to use keys or values with these key words not to be transformed into their boolean values, you have to quote them.

from yaml_extend.

patrickberkeley avatar patrickberkeley commented on May 11, 2024

from yaml_extend.

magynhard avatar magynhard commented on May 11, 2024

I just tried an simple example in IRB:

require 'yaml'
require 'yaml_extend'

YAML.load 'no: so'
# => {false=>"so"} 

File.write "t.yml","no: so"
# => 6

YAML.load_file "t.yml"
# => {false=>"so"} 

YAML.ext_load_file "t.yml"
# => {false=>"so"}

I did not recognize your description, but maybe you have another constellation where a error may happen. Even a simple sample with inheritance worked fine.

You are invited to give an example that does not work in your case, then i will see what I can do for you. πŸ‘πŸ»

from yaml_extend.

patrickberkeley avatar patrickberkeley commented on May 11, 2024

@magynhard you are correct. The issue I'm seeing is if I have multiple keys that are evaluated as false, the last one wins and the previous ones don't appear in the output e.g.,

require 'yaml'

YAML.load '{ no: "no", false: "false" }'
# => {false=>"false"} 

YAML.load '{ false: "false", no: "no" }'
# => {false=>"no"} 

This is normal behavior, but the whole yaml-changing-keys thing is new to me.

from yaml_extend.

magynhard avatar magynhard commented on May 11, 2024

@patrickberkeley this behaviour of YAML was also new to me, to thanks for inspiring me. πŸ‘πŸ»

from yaml_extend.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.