LoginSignup
24
19

More than 5 years have passed since last update.

YAMLの真偽値の扱いに注意。

Last updated at Posted at 2013-07-14

実はYAMLには型があります。

a: 123                     # an integer
b: "123"                   # a string, disambiguated by quotes
c: 123.0                   # a float
d: !!float 123             # also a float via explicit data type prefixed by (!!)
e: !!str 123               # a string, disambiguated by explicit type
f: !!str Yes               # a string via explicit type
g: Yes                     # a boolean True
h: Yes we have No bananas  # a string, "Yes" and "No" disambiguated by context.

123や"123"をinteger, stringと扱うのは普段Ruby等を使用されている方は見慣れてると思いますが、
Yesは boolean の扱いをされる点に注目。(Objective-Cな人は見慣れてますかね)

それが何か問題になるの?

YAMLパーサーの中にはキーにYes(yesも)を利用すると、"true": という様に キー名を変換してしまう パーサーもあるので、命名に注意しないといけません。

こんな感じで

Online_YAML_Parser.png

24
19
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
19