Forum: Ruby Keyword arguments for WIN32OLE?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
764374fb2642bd608c689b3af430ef62?d=identicon&s=25 djlewis (Guest)
on 2008-03-09 23:05
(Received via mailing list)
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.
E97181961afa48102e3a28daab69b904?d=identicon&s=25 Masaki Suketa (Guest)
on 2008-03-10 13:08
(Received via mailing list)
Hello,

djlewis wrote:
 > 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
E97181961afa48102e3a28daab69b904?d=identicon&s=25 Masaki Suketa (Guest)
on 2008-03-10 13:31
(Received via mailing list)
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
8f6f95c4bd64d5f10dfddfdcd03c19d6?d=identicon&s=25 Rick Denatale (rdenatale)
on 2008-03-10 17:32
(Received via mailing list)
On 3/10/08, Masaki Suketa <masaki.suketa@nifty.ne.jp> wrote:
> 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?

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/
E97181961afa48102e3a28daab69b904?d=identicon&s=25 Masaki Suketa (Guest)
on 2008-03-10 22:44
(Received via mailing list)
Rick DeNatale wrote:
 > On 3/10/08, Masaki Suketa <masaki.suketa@nifty.ne.jp> wrote:
 >> 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?

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

   Regards,
   Masaki Suketa
This topic is locked and can not be replied to.