Ruby
Blocks and iterators
> ["foo","bar","baz"].find {|elem| elem == “baz”}
=> “baz”
Types
0x,0b or 0 must precede hex, bin or octal numers
?a or ?\C-c for cltr codes, evaluates to an ascii value. ex. ?0 -> 48
Fun
21.times {|i| a.push((i+?a-1).chr.succ)}; a
Libruby
install_name_tool -id @executable_path/../Frameworks/libruby.dylib Unsis.app/Contents/Frameworks/libruby.dylib
install_name_tool -change /opt/local/lib/libruby.dylib @executable_path/../Frameworks/libruby.dylib Unsis.app/Contents/Frameworks/RubyCocoa.framework/Versions/A/RubyCocoa
Converting to hex (or any base) from Integer (Fixnum, Bignum) or viceversa
100.to_s(16) => 64
“64″.to_i(16) => 100
class Integer
def to_sex
#sprintf(“%x”,self) #backwards compatibile
self.to_s(base=16) #doesn’t work with 1.6.8
end
end