Skip to content

Commit

Permalink
Add NilClass#blank? method, returning true
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWayfer committed Jan 25, 2017
1 parent 6749f10 commit 71baa44
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gorilla-patch.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
Gem::Specification.new do |s|
s.name = 'gorilla-patch'
s.version = '2.1.0'
s.version = '2.1.1'
s.date = Date.today.to_s
s.summary = 'Refining core classes'
s.description = 'Refine Ruby Core classes with methods like Active Support.'
Expand Down
6 changes: 6 additions & 0 deletions lib/gorilla-patch/blank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ def blank?
end
end

refine NilClass do
def blank?
true
end
end

[Array, Hash].each do |klass|
refine klass do
def reject_blank_strings!
Expand Down
4 changes: 4 additions & 0 deletions spec/gorilla-patch/blank_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
it { expect(' a '.blank?).to be false }
end

describe NilClass, '#blank?' do
it { expect(nil.blank?).to be true }
end

describe Array do
let(:array) { [1, nil, '', 'a', [''], {}] }

Expand Down

0 comments on commit 71baa44

Please sign in to comment.