私はWatirとWatir-WebDriverと同時に作業しており、いくつかのクラスを再オープンし、いくつかのメソッドを再定義することにより、それらをより互換性のあるものにしようとしています。私は私が説明できない奇妙な行動に遭遇した。私は何が起こっているのか理解しようとしています。Rubyクラスを再オープンする際の奇妙な問題
これはWindowsでのみ利用可能なwatir-1.7.1で発生しています。
Rubyの1.8.7-P330
RUBYOPT = -rubygems
テスト1.
require 'watir'
Watir::ElementCollections.class_eval do
def new_method
end
end
>ruby open-classes-watir1.rb
open-classes-watir1.rb:3: uninitialized constant Watir::ElementCollections (NameError)
はなぜRubyは有効なクラスを再開文句を言うのでしょうか?問題の
クラスには、次のようになります。
element_collections.rb:
module Watir
#...
class ElementCollections
include Enumerable
#...
end
end
それだけではありません!
試験2
require 'watir'
Watir::IE.class_eval do
end
Watir::ElementCollections.class_eval do # Requires the magic incantation above
def new_method
end
end
>ruby open-classes-watir2.rb
それは、この黒魔術の呪文で今罰金実行:今、これを見て。 Watir :: IEは次のようになります。
ie-class.rb:
module Watir
class IE
include WaitHelper
include Exception
include Container
include PageContainer
#...
end
end
なぜですか?
私は "watir/ie"を必要とします。 –
'watir/element_collections'も必要です – DKroot