Jan-04-2018, 07:19 PM
Ruby has a feature that seems similar, where you can pass a block to a function. Not an annonymous function, but an actual block. Then, within the function, you can
yield
to that block. It's sort of like our iterators/generators, but is used for a whole lot of neat looking magic (like emulating with
). http://ruby-doc.com/docs/ProgrammingRuby...rs.html#UDdef threeTimes yield yield yield end threeTimes { puts "Hello" }produces:
Output:Hello
Hello
Hello
Ok, I guess that's not really similar, it's just the first thing I thought of when it comes to functions doing different things depending on what happens "after" you call it.