Keyword arguments for WIN32OLE?

D

djlewis

Is there a way to pass ~keyword~ arguments to a WIN32OLE method in
Ruby? For example, I've tried...

@selection.Find.Execute( :FindText=>"look
for", :ReplaceWith=>"something else")

.... and the same with the arguments as an explicit hash. They don't
work. I'm reduced to using terribly ugly, error-prone things like...

def replace( find, replace)
@selection.Find.Execute( find, nil, nil, nil, nil, nil, nil, nil,
nil, replace)
end

which is OK once set up. But translating ruby-style hash keyword
arguments to WIN32OLE keyword arguments would be tremendous help.

BTW, the VBA function used above is...

expression.Execute(FindText, MatchCase, MatchWholeWord,
MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward, Wrap,
Format, ReplaceWith, Replace, MatchKashida, MatchDiacritics,
MatchAlefHamza, MatchControl)

Thanks. --David.
 
M

Masaki Suketa

Hello,
Is there a way to pass ~keyword~ arguments to a WIN32OLE method in
Ruby? For example, I've tried...

@selection.Find.Execute( :FindText=>"look
for", :ReplaceWith=>"something else")

Try
@selection.Find.Execute({:FindText=>"look
for", :ReplaceWith=>"something else"})
or
@selection.Find.Execute({"FindText"=>"look
for", "ReplaceWith"=>"something else"})

Regards,
Masaki Suketa
 
M

Masaki Suketa

In Ruby 1.8, hash keys must be String object.
And in Ruby 1.9, hash keys must be String or Symbol object.

So,
@selection.Find.Execute({:FindText=>"look
for", :ReplaceWith=>"something else"})
style is supported in Ruby 1.9
@selection.Find.Execute({"FindText"=>"look
for", "ReplaceWith"=>"something else"})
style is supported in Ruby 1.8 and Ruby 1.9.

Regards,
Masaki Suketa
 
R

Rick DeNatale

In Ruby 1.8, hash keys must be String object.
And in Ruby 1.9, hash keys must be String or Symbol object.

To be clear you're talking about hashes used as arguments to win32ole
methods, not Ruby hashes in general.

Right?
 
M

Masaki Suketa

Rick said:
To be clear you're talking about hashes used as arguments to win32ole
methods, not Ruby hashes in general.

Right?

Yes. I'm talking about Win32OLE methods, not Ruby hashes in general.

Regards,
Masaki Suketa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top