Similar to blocks in Smalltalk and Self, surely?
Still, having worked with ruby a fair bit the past year, it does deliver much of what Smalltalk does (not surprising, as ruby borrows heavily from smalltalk).
https://www.gnu.org/software/smalltalk/manual/html_node/Invo...
Scala even allows multiple blocks to be passed in, used to good effect in the Cats effect `bracket` function, amongst others.
```ruby
def foo &bar
return bar
endfoo {}
# => #<Proc:0x00007ff23783c4e0@(irb):16>
```
But I do agree that I don't quite understand the need for the distinction between procs and methods, or the need for unbound methods; I would think that methods could just be either bound to one object or another, as unbound methods are useless for the fact that they won't work at all unless they are bound.
def find(x, l)
l.each do |y|
return y if y == x
end
end
Where in Lisp you'd use (return-from find x) and in other languages you might pass in a continuation or use a special return value protocol. It's a nice solution for higher order functions that are supposed to feel more language-level.Also, you can pass functions as arguments like in other languages; lambdas behave like you would expect them to.
Similarly, Ruby has nice blocks, and many other languages have similar closure support. But Ruby's support is so built-in from day 1 and heavily used in the standard library and the general culture of Ruby gems. Many of the methods in Enumerable take blocks, making it easy to chain a bunch of functional stuff together, even without any support gems and from the earliest days of Ruby.