在Javascript中,可以使用裸字直接访问属性:
var evil = {"knievel":"evel","daredevil":"fearless"}
evil["knievel"] // "evel"
evil.knievel // "evel"
Ruby中是否有类似的东西而不必evil["knievel"]
?
答案 0 :(得分:2)
require "ostruct"
evil = OpenStruct.new(:knievel => "evel",:daredevil => "fearless")
puts evil.knievel