开发者

Ruby equivalent of hash.key access like in Javascript?

In Javascript properties can be accessed directly with barewords:

var evil = {"knievel":"evel","daredevil":"fearless"}
evil["knievel"] // "evel"
evil.knievel    // "evel"

Is there anything similar i开发者_如何学编程n Ruby without having to do evil["knievel"]?


require "ostruct"

evil = OpenStruct.new(:knievel => "evel",:daredevil => "fearless")
puts evil.knievel
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜