-1

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 in Ruby without having to do evil["knievel"]?

NullUserException
  • 83,810
  • 28
  • 209
  • 234
pankajdoharey
  • 1,562
  • 19
  • 30
  • Really, why does this have a -1? (I'm out of votes or I'd fix the situation.) –  Sep 09 '11 at 22:47
  • Ruby does all sorts of wonderful things may be there was a short cut of some sort where keys could be accessed as methods and return values. – pankajdoharey Sep 09 '11 at 23:54

1 Answers1

2
require "ostruct"

evil = OpenStruct.new(:knievel => "evel",:daredevil => "fearless")
puts evil.knievel
Geo
  • 93,257
  • 117
  • 344
  • 520