From: James Britt Date: 2005-04-19T01:51:33+09:00 Subject: Re: object.["somepropertyOrmethod"] == object.somepropertyOrmethod ? 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? module ECMAtronic def []( m_name ) send( m_name ) end def []=( m_name , val) send( m_name + "=", val ) end end class Foo include ECMAtronic attr_accessor :foo, :bar def initialize( foo = nil, bar = nil ) @foo = foo @bar = bar end def some_method "You have foo = '#@foo' and bar = '#@bar'" end end f = Foo.new( "foo", "bar") f[ "foo" ] = "This is foo" puts f[ "foo" ] puts f[ "some_method" ] James