james_b
4/18/2005 4:52:00 PM
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