From: John Joyce Date: 2007-04-25T22:30:56+09:00 Subject: Re: C++ code into Ruby, I need it fast, no time for RTFM On Apr 25, 2007, at 10:16 PM, Tim Becker wrote: >> We can show you how to do this in Ruby, >> which might be surprisingly different from >> a line-by-line translation of the code you posted. > > But line by line is more fun: > > void p_string(int n, int v[]) > > Throw out return type, argument type and give the method a > rubyesque name: > > def chunky_chunky_bacon(chunky, bacon) > > { > lose the burly bracket. > > int i; > get rid of the local declaration. > > cout<<"\nThe string is : "; > > cout is called STDOUT, you don't need semicolons, and the string > you're printing isn't ruby enough; > > STDOUT << "\nWelcome to the madhouse :" > > for(i=0;i > for loop is different > > for ding_dong in 0..chunky-1 > > > cout< turns into > STDOUT << bacon[dingdong] << " " # this should look familiar by now > end > > end the closely curly brace > } > becomes: > end > > Putting it all together: > > void p_string(int n, int v[]) > { > int i; > cout<<"\nThe string is : "; > for(i=0;i cout< } > > becomes: > > def chunky_chunky_bacon(chunky, bacon) > STDOUT << "\nWelcome to the madhouse :" > for ding_dong in 0..chunky-1 > STDOUT << bacon[ding_dong] << " " > end > end > > > >> >> s >> >> > c'est bon!