From 6ab4f6c9f457fb68a5fc190766b583e04656f9d5 Mon Sep 17 00:00:00 2001 From: Simon Perepelitsa Date: Mon, 16 Aug 2021 22:51:00 +0300 Subject: [PATCH] Fix "method redefined" Ruby warning in verbose mode --- lib/fast_blank.rb | 5 +++++ spec/fast_blank_spec.rb | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) 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)