开发者

Ruby Hash.has_key? returning false for the first key on Windows

I'm having a weird issue with Ruby hashes on windows. I'm loading the following YAML file and parsing it as a hash:

tasks:
  - clone_skeleton, <skeleton_path>
  - summit_capify, <skeleton_path>

I'm using YAML.load() to load the file into a hash. If I print out hash.keys tasks is listed as a key but if I do hash.has_key?("tasks") I get back false. However if I change the yaml to this

directory_structure: 
tasks:
  - clone_skeleton, <skeleton_path>
  - summit_capify, <skeleton_path>

hash.has_key?("tasks") returns true but hash.has_key?("directory_structure") returns false. I haven't tested in Linux but I don't seem to be having this problem on OS X, just Windows. I'm using Ruby 1.9.2 and have tested in Cygwin and using the standard command prompt.

I don't know if this is a ruby bug, a problem with my YAML or something else开发者_如何学JAVA. Any ideas?

UPDATE: Looks like this is fixed in Ruby 1.9.3


Is it possible the keys are Symbols and not Strings? Trying has_key?(:tasks).


Whenever you're debugging, don't do puts hash.keys, but do puts hash.keys.inspect - the latter indicates exactly what's going on.

Or you may want to do puts hash.inspect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜