From: Julian Leviston Date: 2013-03-31T11:37:19+09:00 Subject: Re: Ruby Gotchas presentation slides On 31/03/2013, at 10:55 AM, Dave Aronson wrote: > I recently made available the slides for a presentation I did > recently, on Ruby Gotchas, at: > > https://docs.google.com/presentation/d/1cqdp89_kolr4q1YAQaB-6i5GXip8MHyve8MvQ_1r6_s > > Other than the title, intro, and wrapup, there are 20 slides of > gotchas, from beginner (string interpolation requires double quotes) > to advanced (throw/catch vs. raise/rescue). I'm thinking of turning > it into a series of very brief screencasts. Check it out, let me know > what you think... and if you have any more gotchas you'd like me to > cover. > > Thanks, > Dave This bothers me a little bit, because quite a few of your "gotchas" are about how ruby is ruby. For example, puts 'hi' if 0 is unexpected if you're a C programmer., but not if you're a smalltalker! But it's Ruby, not C or smalltalk! Also, your slide 20 is about a closure, not a loop. This isn't a loop. An Enumerator/Iterator construction is not a loop! You can *think* of them as loops if you like, but an Enumerator is a class that can execute a closure/block many times, passing in different arguments sometimes. Point in case: >> (1..4).map => # >> e = _ => # >> e.next => 1 >> e.next => 2 >> e.next => 3 The Enumerator doesn't "close over" any local variables in the scope of its block... that would make no sense. If that were the case, it wouldn't be a closure anymore, it'd just be code in the main body. If you need variables that stick around, set the variable outside of the lexical scope of the closure, then it'll stick around. Variables aren't "re-un-defined"! (*what* a verbal construction!), they merely fall out of scope when the closure finishes execution each time, so they don't exist anymore. If you're going to do some educating, it'd be good if you made sure the NEW information you are propagating is as correct as possible. >> l = lambda{|val| val + 5} => # >> (1..4).map(&l) => [6, 7, 8, 9] It seems you know all this, but it'd be nice if you put it into your slides :) Otherwise, nice work! Julian