From: dblack@... Date: 2006-07-09T05:05:09+09:00 Subject: Re: Alternative to the Symbol#to_proc hack Hi -- On Sun, 9 Jul 2006, Ashley Moran wrote: > 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 around: > > class String > def everything_in(e) > e.map { |u| u.send(self) } > end > end > > > "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 either. It seems a little odd to send a message to a string, and then have to backtrack to the left, so to speak, and realize that the receiver of the message is actually a message.... It actually feels to me like it's entering the traditional realm of the class method: String.upcase_all %w{ i am an array } (Non-existent, but a typical class-method domain case.) Of course, I'm hopelessly non-edge -- I actually think that: %w{i am an array}.map {|item| item.upcase } is logical, reads nicely left to right, and contains no line noise :-) David -- "To fully realize the potential of Rails, it's crucial that you take the time to fully understand Ruby--and with "Ruby for Rails" David has provided just what you need to help you achieve that goal." -- DAVID HEINEMEIER HANSSON, in the foreword to RUBY FOR RAILS. Complete foreword & sample chapters at http://www.manning.com/black!