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
精彩评论