ruby-changes:23332
From: naruse <ko1@a...>
Date: Wed, 18 Apr 2012 12:59:29 +0900 (JST)
Subject: [ruby-changes:23332] naruse:r35383 (trunk): Revert r35339-35343 because of no tests.
naruse 2012-04-18 12:59:15 +0900 (Wed, 18 Apr 2012) New Revision: 35383 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35383 Log: Revert r35339-35343 because of no tests. * hash.c: Alias ENV.to_h to ENV.to_hash [ref #6276] * lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276] * struct.c: Add Struct#to_h [Feature #6276] * object.c: Add NilClass#to_h [Feature #6276] * hash.c: Add Hash#to_h [Feature #6276] Modified files: trunk/ChangeLog trunk/NEWS trunk/hash.c trunk/lib/ostruct.rb trunk/object.c trunk/struct.c Index: ChangeLog =================================================================== --- ChangeLog (revision 35382) +++ ChangeLog (revision 35383) @@ -53,19 +53,6 @@ * lib/matrix.rb (hermitian?): Bug fix, patch by George Koehler [Bug #6290] [rubyspec:4b9573d7613] -Mon Apr 16 12:13:42 2012 Marc-Andre Lafortune <ruby-core@m...> - - * hash.c: Alias ENV.to_h to ENV.to_hash [ref #6276] - [rubyspec:6587eead7cd1] - * lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276] - [ref #1400] [rubyspec:9e0250b2fc6f] - * struct.c: Add Struct#to_h [Feature #6276] - [ref #4862] [rubyspec:2082ef46d46e] - * object.c: Add NilClass#to_h [Feature #6276] - [ref #5008] [rubyspec:dc5ecddbd608] - * hash.c: Add Hash#to_h [Feature #6276] - [rubyspec:84b7fe3f24d2] - Mon Apr 16 09:42:50 2012 NAKAMURA Usaku <usa@r...> * lib/rubygems/remote_fetcher.rb (Gem::RemoteFetcher#download): should Index: object.c =================================================================== --- object.c (revision 35382) +++ object.c (revision 35383) @@ -1058,24 +1058,7 @@ } /* - * Document-method: to_h - * * call-seq: - * nil.to_h -> {} - * - * Always returns an empty hash. - * - * nil.to_h #=> {} - */ - -static VALUE -nil_to_h(VALUE obj) -{ - return rb_hash_new(); -} - -/* - * call-seq: * nil.inspect -> "nil" * * Always returns the string "nil". @@ -2913,7 +2896,6 @@ rb_define_method(rb_cNilClass, "to_f", nil_to_f, 0); rb_define_method(rb_cNilClass, "to_s", nil_to_s, 0); rb_define_method(rb_cNilClass, "to_a", nil_to_a, 0); - rb_define_method(rb_cNilClass, "to_h", nil_to_h, 0); rb_define_method(rb_cNilClass, "inspect", nil_inspect, 0); rb_define_method(rb_cNilClass, "&", false_and, 1); rb_define_method(rb_cNilClass, "|", false_or, 1); Index: lib/ostruct.rb =================================================================== --- lib/ostruct.rb (revision 35382) +++ lib/ostruct.rb (revision 35383) @@ -101,28 +101,33 @@ end # - # Converts the OpenStruct to a hash with keys representing - # each attribute (as symbols) and their corresponding values - # Example: + # Provides marshalling support for use by the Marshal library. Returning the + # underlying Hash table that contains the functions defined as the keys and + # the values assigned to them. # - # require 'ostruct' - # data = OpenStruct.new("country" => "Australia", :population => 20_000_000) - # data.to_h # => {:country => "Australia", :population => 20000000 } + # require 'ostruct' # - def to_h - @table.dup - end - + # person = OpenStruct.new + # person.name = 'John Smith' + # person.age = 70 # - # Provides marshalling support for use by the Marshal library. + # person.marshal_dump # => { :name => 'John Smith', :age => 70 } # def marshal_dump @table end # - # Provides marshalling support for use by the Marshal library. + # Provides marshalling support for use by the Marshal library. Accepting + # a Hash of keys and values which will be used to populate the internal table # + # require 'ostruct' + # + # event = OpenStruct.new + # hash = { 'time' => Time.now, 'title' => 'Birthday Party' } + # event.marshal_load(hash) + # event.title # => 'Birthday Party' + # def marshal_load(x) @table = x @table.each_key{|key| new_ostruct_member(key)} Index: struct.c =================================================================== --- struct.c (revision 35382) +++ struct.c (revision 35383) @@ -586,31 +586,6 @@ return rb_ary_new4(RSTRUCT_LEN(s), RSTRUCT_PTR(s)); } -/* - * call-seq: - * struct.to_h -> hash - * - * Returns the values for this instance as a hash with keys - * corresponding to the instance variable name. - * - * Customer = Struct.new(:name, :address, :zip) - * joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) - * joe.to_h[:address] #=> "123 Maple, Anytown NC" - */ - -static VALUE -rb_struct_to_h(VALUE s) -{ - VALUE h = rb_hash_new(); - VALUE members = rb_struct_members(s); - long i; - - for (i=0; i<RSTRUCT_LEN(s); i++) { - rb_hash_aset(h, rb_ary_entry(members, i), RSTRUCT_PTR(s)[i]); - } - return h; -} - /* :nodoc: */ VALUE rb_struct_init_copy(VALUE copy, VALUE s) @@ -986,7 +961,6 @@ rb_define_method(rb_cStruct, "inspect", rb_struct_inspect, 0); rb_define_alias(rb_cStruct, "to_s", "inspect"); rb_define_method(rb_cStruct, "to_a", rb_struct_to_a, 0); - rb_define_method(rb_cStruct, "to_h", rb_struct_to_h, 0); rb_define_method(rb_cStruct, "values", rb_struct_to_a, 0); rb_define_method(rb_cStruct, "size", rb_struct_size, 0); rb_define_method(rb_cStruct, "length", rb_struct_size, 0); Index: hash.c =================================================================== --- hash.c (revision 35382) +++ hash.c (revision 35383) @@ -1452,30 +1452,6 @@ return hash; } -/* - * call-seq: - * hsh.to_h -> hsh or new_hash - * - * Returns +self+. If called on a subclass of Hash, converts - * the receiver to a Hash object. - */ - -static VALUE -rb_hash_to_h(VALUE hash) -{ - if (rb_obj_class(hash) != rb_cHash) { - VALUE ret = rb_hash_new(); - if (!RHASH_EMPTY_P(hash)) - RHASH(ret)->ntbl = st_copy(RHASH(hash)->ntbl); - if (FL_TEST(hash, HASH_PROC_DEFAULT)) { - FL_SET(ret, HASH_PROC_DEFAULT); - } - RHASH_IFNONE(ret) = RHASH_IFNONE(hash); - return ret; - } - return hash; -} - static int keys_i(VALUE key, VALUE value, VALUE ary) { @@ -3078,8 +3054,7 @@ /* * call-seq: - * ENV.to_hash -> hash - * ENV.to_h -> hash + * ENV.to_hash -> Hash * * Creates a hash with a copy of the environment variables. * @@ -3358,7 +3333,6 @@ rb_define_method(rb_cHash,"rehash", rb_hash_rehash, 0); rb_define_method(rb_cHash,"to_hash", rb_hash_to_hash, 0); - rb_define_method(rb_cHash,"to_h", rb_hash_to_h, 0); rb_define_method(rb_cHash,"to_a", rb_hash_to_a, 0); rb_define_method(rb_cHash,"inspect", rb_hash_inspect, 0); rb_define_alias(rb_cHash, "to_s", "inspect"); @@ -3469,7 +3443,6 @@ rb_define_singleton_method(envtbl,"key?", env_has_key, 1); rb_define_singleton_method(envtbl,"value?", env_has_value, 1); rb_define_singleton_method(envtbl,"to_hash", env_to_hash, 0); - rb_define_singleton_method(envtbl,"to_h", env_to_hash, 0); rb_define_singleton_method(envtbl,"assoc", env_assoc, 1); rb_define_singleton_method(envtbl,"rassoc", env_rassoc, 1); Index: NEWS =================================================================== --- NEWS (revision 35382) +++ NEWS (revision 35383) @@ -21,13 +21,7 @@ * added method: * added Enumerable#lazy method for lazy enumeration. - * ENV - * aliased method: - * ENV.to_h is a new alias for ENV.to_hash - * Hash - * added method: - * added Hash#to_h as explicit conversion method, like Array#to_a. * extended method: * Hash#default_proc= can be passed nil to clear the default proc. @@ -47,20 +41,11 @@ * added LoadError#path method to return the file name that could not be loaded. - * NilClass - * added method: - * added nil.to_h which returns {} - * Signal * incompatible changes: * Signal.trap raises ArgumentError when :SEGV, :BUS, :ILL, :FPE, :VTALRM are specified. - * Struct - * added method: - * added Struct#to_h returning values with keys corresponding to the - instance variable names. - * Time * change return value: * Time#to_s returned encoding defaults to US-ASCII but automatically @@ -78,10 +63,6 @@ * Net::IMAP.default_ssl_port * Net::IMAP.default_imaps_port -* ostruct - * new methods: - * OpenStruct#to_h converts the struct to a hash. - * pathname * extended method: * Pathname#find returns an enumerator if no block is given. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/