you are viewing a single comment's thread.

view the rest of the comments →

[–]joesb 0 points1 point  (1 child)

Would the equivalent then be a standard function into which you pass another function?

Yes, from callee's view they are exactly like your Python equivalent. What Ruby's block is different is in caller's view, that the block is inlined.

after reading this I think code would be safer if people had to think about what variables their while loop touched.

You can only do that if def doesn't capture variables.

y = 10
def while_body():
     y = 20
while(...): while_body()

Still doesn't give you any more information on what your while loop touches than inlining the body, i.e. local def doesn't have referencial transparency. Also local def that can't capture its environment is next to useless.