Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "method redefined" Ruby warning in verbose mode #30

Merged
merged 1 commit into from Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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