Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can teach <array>.each { |<elem>| <code> } exactly as you would teach for <elem> in <array> do <code> end. The .each variant allows the student to discover a rich palette of correlations as he progresses, the for do end variant is a dead end he needs to forget sooner or later. As a student, I know precisely which variant I'd chose. Do you?


So, define a closure in terms that someone who has just learned what a variable is can understand.

"Just memorize this syntax and do it" is not allowed.


My issue here is that the for version is pretty much exactly "Just memorize this syntax and do it"


I already did:

> There is a function "each" that applies to arrays. "Each", for each element in the array, binds "elem" to the element value, then executes the body of the code block. The code applies "each" to array "arr" and executes "puts elem" for each element.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: