From: dblack@... Date: 2002-10-09T13:09:26+09:00 Subject: Re: reproducable bug Hi -- On Wed, 9 Oct 2002, HelloTree, Inc. wrote: > Hello, > > So here's the code: > > ----- BEGIN CODE ----- > > require 'socket' > > ... > > sock = TCPSocket.new (SERVER_ADDRESS, SERVER_PORT) > > a = 'a' > a[0..0] = '' > sock.puts(String.new(a)) # CRASH! > > puts 'We never get here.' String.new wants a string (literal or otherwise) as its argument. a is an Array, so it doesn't work: irb(main):003:0> a = [0..0] [0..0] irb(main):004:0> puts String.new(a) TypeError: failed to convert Array into String from (irb):4:in `initialize' from (irb):4:in `new' from (irb):4 This is a case where, if you wanted, you could use #to_str, which is called in cases where objects need to masquerade as strings: irb(main):005:0> def a.to_str; to_s; end nil irb(main):006:0> puts String.new(a) 0..0 Or you could just do: puts String.new(a.to_s) David -- David Alan Black | Register for RubyConf 2002! home: dblack@candle.superlink.net | November 1-3 work: blackdav@shu.edu | Seattle, WA, USA Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com