Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ToNil

Cast everything to nil!
Also, convert to nil only if not already nil.

## Installation

Expand All @@ -26,6 +27,11 @@ Or install it yourself as:
"Yet another shitty gem".to_nil # nil
"Your fat boss".to_nil # nil
nil.to_nil # nil

nil.to_nil? # nil
?0.to_nil? # nil
%w(nil).to_nil? # nil
/nil/.to_nil? # nil
```

## Contributing
Expand Down
5 changes: 4 additions & 1 deletion lib/to_nil.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module ObjectExtension
def to_nil
nil
end
def to_nil?
nil
end
end
end

Expand All @@ -14,4 +17,4 @@ class Object

class BasicObject
include ::ToNil::ObjectExtension
end
end
12 changes: 12 additions & 0 deletions spec/to_nil_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,21 @@
it "returns nil for a #{klass} instance" do
expect(klass.new.to_nil).to be_nil
end

it "returns nil for nil.to_nil? for a #{klass} instance" do
expect(klass.new.to_nil?).to be_nil
end
end

it "returns nil for nil.to_nil" do
expect(nil.to_nil).to be_nil
end

it "returns nil for nil.to_nil? on nil" do
expect(nil.to_nil?).to be_nil
end

it "returns nil for nil.to_nil? on non-nil" do
expect(?0.to_nil?).to be_nil
end
end