From: James Edward Gray II Date: 2007-08-22T21:35:39+09:00 Subject: Re: How to "cast" in Ruby On Aug 22, 2007, at 7:29 AM, Kaldrenon wrote: > On Aug 21, 10:11 pm, "Logan Capaldo" wrote: >> On 8/21/07, Kaldrenon wrote: >>> It's also exactly the same number of characters. >> >> I had to count to be sure, but you are indeed correct. :) I just >> think >> "#{foo}" looks busier than foo.to_s > > By itself, I happen to agree, but I tend to dislike long method call > chains as in the original example. They both do the same thing, so > it's just a preference thing, I think. Well, one definitely has Ruby doing more work: #!/usr/bin/env ruby -wKU require "benchmark" TESTS = 1_000_000 Benchmark.bmbm do |results| results.report("iterpolation:") { TESTS.times { "#{TESTS}" } } results.report("to_s:") { TESTS.times { TESTS.to_s } } end # >> Rehearsal ------------------------------------------------- # >> iterpolation: 1.400000 0.000000 1.400000 ( 1.404947) # >> to_s: 0.820000 0.000000 0.820000 ( 0.817229) # >> ---------------------------------------- total: 2.220000sec # >> # >> user system total real # >> iterpolation: 1.400000 0.000000 1.400000 ( 1.395974) # >> to_s: 0.820000 0.000000 0.820000 ( 0.820689) __END__ James Edward Gray II