mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	Alias ENV.merge! as ENV.update
[Feature #15947] Closes: https://github.com/ruby/ruby/pull/2246
This commit is contained in:
		
							parent
							
								
									3b2d11ad90
								
							
						
					
					
						commit
						d01fd82187
					
				
					 4 changed files with 34 additions and 21 deletions
				
			
		
							
								
								
									
										3
									
								
								hash.c
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								hash.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -5788,6 +5788,8 @@ env_update_i(VALUE key, VALUE val)
 | 
			
		|||
 * call-seq:
 | 
			
		||||
 *   ENV.update(hash)                                        -> Hash
 | 
			
		||||
 *   ENV.update(hash) { |name, old_value, new_value| block } -> Hash
 | 
			
		||||
 *   ENV.merge!(hash)                                        -> Hash
 | 
			
		||||
 *   ENV.merge!(hash) { |name, old_value, new_value| block } -> Hash
 | 
			
		||||
 *
 | 
			
		||||
 * Adds the contents of +hash+ to the environment variables.  If no block is
 | 
			
		||||
 * specified entries with duplicate keys are overwritten, otherwise the value
 | 
			
		||||
| 
						 | 
				
			
			@ -6059,6 +6061,7 @@ Init_Hash(void)
 | 
			
		|||
    rb_define_singleton_method(envtbl, "invert", env_invert, 0);
 | 
			
		||||
    rb_define_singleton_method(envtbl, "replace", env_replace, 1);
 | 
			
		||||
    rb_define_singleton_method(envtbl, "update", env_update, 1);
 | 
			
		||||
    rb_define_singleton_method(envtbl, "merge!", env_update, 1);
 | 
			
		||||
    rb_define_singleton_method(envtbl, "inspect", env_inspect, 0);
 | 
			
		||||
    rb_define_singleton_method(envtbl, "rehash", env_none, 0);
 | 
			
		||||
    rb_define_singleton_method(envtbl, "to_a", env_to_a, 0);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										8
									
								
								spec/ruby/core/env/merge_spec.rb
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								spec/ruby/core/env/merge_spec.rb
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
require_relative '../../spec_helper'
 | 
			
		||||
require_relative 'shared/update'
 | 
			
		||||
 | 
			
		||||
ruby_version_is "2.7" do
 | 
			
		||||
  describe "ENV.merge!" do
 | 
			
		||||
    it_behaves_like :env_update, :merge!
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										21
									
								
								spec/ruby/core/env/shared/update.rb
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								spec/ruby/core/env/shared/update.rb
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,21 @@
 | 
			
		|||
describe :env_update, shared: true do
 | 
			
		||||
  it "adds the parameter hash to ENV" do
 | 
			
		||||
    ENV["foo"].should == nil
 | 
			
		||||
    ENV.send @method, "foo" => "bar"
 | 
			
		||||
    ENV["foo"].should == "bar"
 | 
			
		||||
    ENV.delete "foo"
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "yields key, the old value and the new value when replacing entries" do
 | 
			
		||||
    ENV.send @method, "foo" => "bar"
 | 
			
		||||
    ENV["foo"].should == "bar"
 | 
			
		||||
    ENV.send(@method, "foo" => "boo") do |key, old, new|
 | 
			
		||||
      key.should == "foo"
 | 
			
		||||
      old.should == "bar"
 | 
			
		||||
      new.should == "boo"
 | 
			
		||||
      "rab"
 | 
			
		||||
    end
 | 
			
		||||
    ENV["foo"].should == "rab"
 | 
			
		||||
    ENV.delete "foo"
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										23
									
								
								spec/ruby/core/env/update_spec.rb
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										23
									
								
								spec/ruby/core/env/update_spec.rb
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -1,25 +1,6 @@
 | 
			
		|||
require_relative '../../spec_helper'
 | 
			
		||||
require_relative 'shared/update'
 | 
			
		||||
 | 
			
		||||
describe "ENV.update" do
 | 
			
		||||
 | 
			
		||||
  it "adds the parameter hash to ENV" do
 | 
			
		||||
    ENV["foo"].should == nil
 | 
			
		||||
    ENV.update "foo" => "bar"
 | 
			
		||||
    ENV["foo"].should == "bar"
 | 
			
		||||
    ENV.delete "foo"
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "yields key, the old value and the new value when replacing entries" do
 | 
			
		||||
    ENV.update "foo" => "bar"
 | 
			
		||||
    ENV["foo"].should == "bar"
 | 
			
		||||
    ENV.update("foo" => "boo") do |key, old, new|
 | 
			
		||||
      key.should == "foo"
 | 
			
		||||
      old.should == "bar"
 | 
			
		||||
      new.should == "boo"
 | 
			
		||||
      "rab"
 | 
			
		||||
    end
 | 
			
		||||
    ENV["foo"].should == "rab"
 | 
			
		||||
    ENV.delete "foo"
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it_behaves_like :env_update, :update
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue