[Wtr-general] Method Names as variables?
Michael Bolton
mb at michaelbolton.net
Tue Apr 18 17:03:22 EDT 2006
You may be too bilingual; I see where alldocs is initialized, but I don't
see where todosdocs is initialized.
---Michael B.
_____
From: wtr-general-bounces at rubyforge.org
[mailto:wtr-general-bounces at rubyforge.org] On Behalf Of Rodrigo Julian
Martin
Sent: April 18, 2006 4:27 PM
To: wtr-general at rubyforge.org
Subject: Re: [Wtr-general] Method Names as variables?
Hello Keith!
Thanks for the quick answer, but I'm afraid that this is not what I'm
looking for.
I have written a function which search objects from a page, passing a
propertie and a value as parameters.
This is the function:
def ENRA_FindObjects(propertie, value)
$vector_fobjects=nil
$vector_fobjects=Array.new
j=0
alldocs=nil
alldocs=$browser.document.body.all
count=$browser.document.body.all.length
$vector_search=nil
$vector_search=Array.new
for i in 0..count-1 do
if (todosdocs[i.to_s]."#{propertie}=="#{value}")
$vector_search[j]=todosdocs[i.to_s]
j+=1
end
end
return($vector_search)
end
So, I load a page with a browser, and execute this function with, let's say:
array_objects=ENRA_FindObjects("className","button")
I hope the question is more clear now.
How can I write this properly? -->
todosdocs[i.to_s]."#{propertie}=="#{value}" ,
In order that the propertie could be defined by a parameter?
Thank you so much for your time.
Cheers
Rodrigo Julian Martin
_____
From: Keith Lancaster [mailto:klancaster1957 at gmail.com]
Sent: Martes, 18 de Abril de 2006 05:17 p.m.
To: wtr-general at rubyforge.org; Rodrigo Julian Martin
Subject: Re: [Wtr-general] Method Names as variables?
I am assuming Item(80) in your example is an object.
In Ruby, you can use the "send" method to call a function.
Example:
class MyClass
def my_function
puts "in my function"
end
end
c = MyClass.new
function_name = "my_function"
c.send(function_name)
HTH,
Keith
On 4/18/06 3:00 PM, "Rodrigo Julian Martin" <rodrigo.martin at enratio.com>
wrote:
Hello!
I have another code question.
Can I call an object method by using a variable?
I've tried something like this:
propertie="className"
a = Item(80).'#{propertie}'
And obviously doesn't work.
I've also tried:
a = Item(80).{propertie}
but this is a call to a hash.
Any help would be really appreciated.
Thanks in Advance!
Rodrigo Julian Martin
_____
_______________________________________________
Wtr-general mailing list
Wtr-general at rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/wtr-general/attachments/20060418/b50a25e4/attachment.html
More information about the Wtr-general
mailing list