Alternative to the Symbol#to_proc hack

I’ve always been in two minds about the Symbol#to_proc hack, it’s
clever but adds a bit of line noise. Then I figured you can turn it

class String
def everything_in(e) { |u| u.send(self) }

“upcase”.everything_in %w( i am an array )
=> [“I”, “AM”, “AN”, “ARRAY”]

It’s a bit nasty because in 1.8 it can call private methods, but I
kinda like it. And it’s not much use if you want to pass arguments

Not sure if it’s been done before either.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs