4

一起使用 Watir 和 Highline 时,我遇到了一些奇怪的功能。

这是一个简单的例子:

require 'highline/import'
comp = ask("Company?  ") { |q| q.default = "MySuperCompany" }
puts comp

require 'watir'
comp = ask("Company?  ") { |q| q.default = "MySuperCompany" }
puts comp

这是一个输出:

Company?  |MySuperCompany|
MySuperCompany
[Company?  ] =>
Company?

也许这是一个错误?我还在 highline 的文档中发现,

如果在调用 ask() 之前设置了 @question,则忽略参数并使用该对象(必须是 HighLine::Question)来驱动进程。

抱歉,我不是红宝石大师 :-(

4

1 回答 1

5

Confirmed. It really behaves like that.

Željko: http://highline.rubyforge.org/

grundic: The problem is not related with Watir itself, but it is related with another library called s4t-utils (http://s4t-utils.rubyforge.org/), which also has a "ask" method behaving similar to HighLine's "ask". s4t-utils is a dependendent of gem "user-choices", which in turn is dependent of "commonwatir" which is a Watir's dependency. So, after you issue "require 'watir'", then s4t-utils is loaded thus "ask" method is overridden.

You could use HighLine.new.ask instead of just "ask" to solve the problem:

require "highline/import"
comp = ask("Company?  ") { |q| q.default = "MySuperCompany" }
puts comp

require 'watir'
comp = ask("Company?  ") { |q| q.default = "MySuperCompany" }
puts comp

comp = HighLine.new.ask("Company?  ") { |q| q.default = "MySuperCompany" }
puts comp

Produces:

Company?  |MySuperCompany|  my
my
[Company?  ] => my
my
Company?  |MySuperCompany|  my
my

Jarmo Pertman

于 2010-05-28T07:18:01.537 回答