From: Phrogz Date: 2008-02-06T09:09:56+09:00 Subject: Re: how can I use variable as a attribute name On Feb 5, 2:23 pm, Darin Duphorn wrote: > I'm unable to use the attribute name (variable) to verify the button > with the attribute value exists. > > I've tried the following: > > #Set Variables > $attribute_nm = "type" > $attribute_val = "submit" > > #Verify Button Exists > if $ie.button(:$attribute_nm,$attribute_val).exists? > > #Verify Button Exists > if $ie.button(:+$attribute_nm,$attribute_val).exists? > > #Verify Button Exists > if $ie.button($attribute_nm,$attribute_val).exists? Wow, that's a lot of global variables. If it's a symbol you want: irb(main):001:0> f = "foo" => "foo" irb(main):002:0> p f.to_sym, f.intern, :"#{f}" :foo :foo :foo If it's a method call you're trying to do based on the variable, see the Object#send method: C:\>ri Object#send ------------------------------------------------------------ Object#send obj.send(symbol [, args...]) => obj obj.__send__(symbol [, args...]) => obj ------------------------------------------------------------------------ Invokes the method identified by _symbol_, passing it any arguments specified. You can use +__send__+ if the name +send+ clashes with an existing method in _obj_. class Klass def hello(*args) "Hello " + args.join(' ') end end k = Klass.new k.send :hello, "gentle", "readers" #=> "Hello gentle readers"