Skip to content

Commit

Permalink
Fix "method redefined" Ruby warning in verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
semaperepelitsa committed Aug 16, 2021
1 parent c2aa400 commit 6ab4f6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/fast_blank.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
9 changes: 8 additions & 1 deletion spec/fast_blank_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 6ab4f6c

Please sign in to comment.