From: Brian Candler Date: 2003-05-08T15:54:56+09:00 Subject: Re: access a variables name? On Thu, May 08, 2003 at 02:48:39PM +0900, Meinrad Recheis wrote: > > a.instance_variable_get("@bar") #>> 1 > > a.instance_variable_set("@baz",2) > > > but, what's that? i didn't find instance_variable_get/set in ruby's > documentation It's a recent feature - it's not in 1.6.8 but it's in 1.8.0p2 You can query directly what methods are available in an object: e.g. irb(main):005:0> class Foo; end => nil irb(main):006:0> a=Foo.new => # irb(main):007:0> a.public_methods => ["untaint", "kind_of?", "type", "instance_variable_get", "inspect", "frozen?", "taint", "send", "private_methods", "__id__", "method", "=~", "to_a", "eql?", "dup", "hash", "singleton_methods", "display", "nil?", "freeze", "is_a?", "class", "instance_variable_set", "methods", "__send__", "instance_eval", "extend", "object_id", "instance_variables", "instance_of?", "to_s", "copy_object", "id", "protected_methods", "equal?", "respond_to?", "clone", "tainted?", "==", "public_methods", "==="]