Skip to content

Commit

Permalink
Merge pull request #30 from semaperepelitsa/method-redefined
Browse files Browse the repository at this point in the history
Fix "method redefined" Ruby warning in verbose mode
  • Loading branch information
SamSaffron committed Aug 16, 2021
2 parents c2aa400 + 6ab4f6c commit edeb185
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
@@ -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
@@ -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 edeb185

Please sign in to comment.