Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: rubinius/rubinius
base: becf59ad6f
...
head fork: rubinius/rubinius
compare: 8141ff4169
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 21 additions and 3 deletions.
  1. +5 −1 kernel/common/env.rb
  2. +16 −2 spec/ruby/core/env/delete_spec.rb
6 kernel/common/env.rb
View
@@ -57,7 +57,11 @@ def each
def delete(key)
existing_value = self[key]
- self[key] = nil if existing_value
+ if existing_value
+ self[key] = nil
+ elsif block_given?
+ yield key
+ end
existing_value
end
18 spec/ruby/core/env/delete_spec.rb
View
@@ -1,9 +1,23 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.delete" do
- it "removes the variable and return its value" do
+ after(:each) do
+ ENV.delete("foo")
+ end
+
+ it "removes the variable from the environment" do
ENV["foo"] = "bar"
- ENV.delete("foo").should == "bar"
+ ENV.delete("foo")
ENV["foo"].should == nil
end
+
+ it "returns the previous value" do
+ ENV["foo"] = "bar"
+ ENV.delete("foo").should == "bar"
+ end
+
+ it "yields the name to the given block if the named environment variable does not exist" do
+ ENV.delete("foo") { |name| ScratchPad.record name }
+ ScratchPad.recorded.should == "foo"
+ end
end

No commit comments for this range

Something went wrong with that request. Please try again.