From: Robert Klemme Date: 2005-04-19T02:14:35+09:00 Subject: Re: object.["somepropertyOrmethod"] == object.somepropertyOrmethod ? "mark sparshatt" schrieb im Newsbeitrag news:4263E07F.2010503@yahoo.co.uk... > falcon wrote: >> Does Ruby allow javascript like invocation of methods (or access to >> properties) like this: >> someProperty = "nameOfStudent" >> Object[someProperty] >> >> rather than just Object.nameOfStudent? > > The way to do this would be to use the send method > > Object.send(someProperty) > > Or you could define a [] method for your class > > def [](propertyname) > self.send(propertyname) > end > > then you'd be able to use > > Object[someProperty] You can as well use a Hash instead. You might also want to look at OpenStruct, which might help you, too. An OpenStruct happily accepts every getter or setter when invoked: >> require 'ostruct' => true >> o = OpenStruct.new => >> o.foo => nil >> o.foo = "bar" => "bar" >> o.foo => "bar" >> o => Kind regards robert