diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-04-18 03:59:15 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-04-18 03:59:15 +0000 |
commit | 62c9ecfa122da546af36ed5a31e8696c62ced036 (patch) | |
tree | 40fd17671b67821d024a1d47beb5a22d1faad43b /struct.c | |
parent | cc6ab53f592016daf6f4ef0075e4f33f365d638f (diff) |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 26 |
1 files changed, 0 insertions, 26 deletions
@@ -586,31 +586,6 @@ rb_struct_to_a(VALUE s) 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 @@ Init_Struct(void) 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); |