diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-09-07 16:33:08 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-09-07 16:33:08 +0000 |
commit | d1cb9e75d054d06f0a80aeb112b894e82952c6d0 (patch) | |
tree | 125731f69051512ba26caaa86c09f7d305efa03d /hash.c | |
parent | b06a278942c0041fd4b81df2ac3c10a29eb40a21 (diff) | |
download | ruby-d1cb9e75d054d06f0a80aeb112b894e82952c6d0.tar.gz |
* array.c (Init_Array): #to_s to be an alias to #inspect.
[EXPERIMENTAL] [ruby-dev:29520]
* hash.c (Init_Hash): ditto.
* lib/mkmf.rb (create_makefile): replace "print array" by
"print *array".
* mkconfig.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 32 |
1 files changed, 5 insertions, 27 deletions
@@ -1147,9 +1147,13 @@ inspect_hash(VALUE hash, VALUE dummy, int recur) /* * call-seq: + * hsh.to_s => string * hsh.inspect => string * * Return the contents of this hash as a string. + * + * h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 } + * h.to_s #=> "{\"a\"=>100, \"c\"=>300, \"d\"=>400}" */ static VALUE @@ -1160,32 +1164,6 @@ rb_hash_inspect(VALUE hash) return rb_exec_recursive(inspect_hash, hash, 0); } -static VALUE -to_s_hash(VALUE hash, VALUE dummy, int recur) -{ - if (recur) return rb_str_new2("{...}"); - return rb_ary_to_s(rb_hash_to_a(hash)); -} - -/* - * call-seq: - * hsh.to_s => string - * - * Converts <i>hsh</i> to a string by converting the hash to an array - * of <code>[</code> <i>key, value</i> <code>]</code> pairs and then - * converting that array to a string using <code>Array#join</code> with - * the default separator. - * - * h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 } - * h.to_s #=> "a100c300d400" - */ - -static VALUE -rb_hash_to_s(VALUE hash) -{ - return rb_exec_recursive(to_s_hash, hash, 0); -} - /* * call-seq: * hsh.to_hash => hsh @@ -2299,7 +2277,7 @@ Init_Hash(void) rb_define_method(rb_cHash,"to_hash", rb_hash_to_hash, 0); rb_define_method(rb_cHash,"to_a", rb_hash_to_a, 0); - rb_define_method(rb_cHash,"to_s", rb_hash_to_s, 0); + rb_define_method(rb_cHash,"to_s", rb_hash_inspect, 0); rb_define_method(rb_cHash,"inspect", rb_hash_inspect, 0); rb_define_method(rb_cHash,"==", rb_hash_equal, 1); |