Embed Notice
HTML Code
Corresponding Notice
- Embed this notice@hazlin
> And, remembered that I've never really looked at ruby. (but I've often heard it talked about)
Oh, wow. It's basically what I have been using for work since forever, so it feels boring to me sometimes, like not really worth mentioning. But it's really great for mangling arrays and strings, lot of easy support for talking to random databases (SQL or Redis or whichever), very nice REPL, so that makes it useful for interactively poking at data. There's some disdain for it, but it's like Lisp, Smalltalk, and Perl had a baby. Like, the fact that you can pass a block to gsub is already enough to put it on top of most string-manglers:
irb(main):001:0> i=0; "This is a test of the string substitutions.".gsub(/i/) { |m| "[number #{i+=1}]" }
=> "Th[number 1]s [number 2]s a test of the str[number 3]ng subst[number 4]tut[number 5]ons."
It's what I usually reach for if it looks like awk won't cut it.
> Any thing else you can point me at to see the shine of ruby?
I still like "_why's (Poignant) Guide to Ruby", but when he pushed that out, I already knew Ruby. The way I learned was I half-read and half-skimmed the Pickaxe book (which is now notorious for being a terrible way to learn the language) and basically having done some Perl and some Common Lisp, I was able to more or less guess how things like map worked, and I hung out on the mailing list. Back in The Day, if someone managed to use Ruby at work, they'd send email to the list, and people were on there puzzling things out or making up challenges or doing code golf.
[1,2,3].map{|i|i**2}.inject(&:+)
I think the best way to learn Ruby is the REPL. Like fire up irb and go for it. Matz's goal was to make a language that was fun to use, and it's pretty successful at that.