If I have a YAML file like

2.1: my product version

without any quotation marks, Ruby will treat the 2.1 as a Float (at least under Syck - I'm not sure about Psych).

Are there any risks in using a Float as a hash's key, so long as all of the other occurences of the key are either from a YAML file or literals from Ruby?

  • A version "number" is not actually a floating point number or even a number of any kind, it is more like sequence of integers ([2,1,11]) that is written in a peculiar way (2.1.11). So the problem behind the question is moot :) Jan 3, 2012 at 6:17
  • @muistooshort: My question is can I be lazy and not use quotation marks to escape it or not. Jan 3, 2012 at 6:57
  • I haven't tried it with Hash, but it causes problems with RBTree (at least with Psych): '@9.884112959068247e-09' is not allowed as an instance variable name
    – Translunar
    Sep 28, 2013 at 23:28


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.