diff --git a/lib/fast_blank.rb b/lib/fast_blank.rb index cf370a6..39fdced 100644 --- a/lib/fast_blank.rb +++ b/lib/fast_blank.rb @@ -1,3 +1,8 @@ +class ::String + # Explicitly undefine method before redefining to avoid Ruby warnings. + undef_method(:blank?) if method_defined?(:blank?) +end + case RUBY_ENGINE when 'jruby' require 'fast_blank.jar' diff --git a/spec/fast_blank_spec.rb b/spec/fast_blank_spec.rb index bed89e9..4317b0f 100644 --- a/spec/fast_blank_spec.rb +++ b/spec/fast_blank_spec.rb @@ -1,11 +1,18 @@ -require 'fast_blank' +$VERBOSE = true class ::String + # Stub the original method to make sure it is redefined correctly. + def blank? + raise NotImplementedError + end + def blank2? /\A[[:space:]]*\z/ === self end end +require 'fast_blank' + describe String do it "works" do expect("".blank?).to eq(true)