a = "some
data"a = "some\ndata"
Below are some things I have found to be useful. It's basically a list of things that you should probably not use except for codegolf :) Alot of this I learned from talking with people since I joined, so there are probably lots of tricks like this I don't know yet, hopefully someone can add to this.
?d for numbers like 100, etc
a*i+=1while gets (short while, throwing in = / += at end of statements, no space between while)
using implied $_ in gets, gsub, scan (note gsub = $_.gsub!, no need for ! point)
$* for array initialized to [], but cannot use = operator on it although you can write to it in other ways
$/ for string initialized to "\n"
$$ for a huge number (process number)
? : operator as well as using i==0&&j+=7 instead of j+=7 if i==0
% operator for formatting strings, very useful
a*' ' instead of a.join
1/0 to exit
%w(...) for space separated array of strings
<< to append to arrays/strings
a=gets.splita=gets(nil).split("\n")a,b=readlines to read multiple lines
statement while expression
Examples:
$><< to output
a,b=readlines to read multiple lines
I'm very new to ruby myself and I find myself totally addicted to this type of game, however I feel that sharing some information about general Ruby tips for producing smaller code could help some of the new guys get rolling on the challenges. I, for one, don't know where to look to find out many of these "tricks" that those coding in the language for some time take for granted.
Thanks,
Drew