Comments on: A Puzzle for Polite Ruby Programmers https://blog.mattwynne.net/2011/04/10/a-puzzle-for-polite-ruby-programmers/ Matt Wynne taking it one tea at a time Wed, 21 Aug 2019 12:55:30 +0000 hourly 1 https://wordpress.org/?v=6.2 By: Samnang Chhun https://blog.mattwynne.net/2011/04/10/a-puzzle-for-polite-ruby-programmers/comment-page-1/#comment-1369 Sun, 17 Jul 2011 17:11:10 +0000 http://blog.mattwynne.net/2011/04/10/a-puzzle-for-polite-ruby-programmers/#comment-1369 Here’s my revision: https://gist.github.com/1087802

I make it into shorter by using definesingletonmethod.

]]>
By: James Adam https://blog.mattwynne.net/2011/04/10/a-puzzle-for-polite-ruby-programmers/comment-page-1/#comment-1297 Sun, 10 Apr 2011 17:05:44 +0000 http://blog.mattwynne.net/2011/04/10/a-puzzle-for-polite-ruby-programmers/#comment-1297 Here’s my attempt: https://gist.github.com/912526

Basically, if you use define_method, you can get closure-like behaviour around the method body, since this is defined as a block.

I suspect this will only work in Ruby 1.9.2 because of some of the restrictions for defining block arguments in earlier versions of Ruby.

I’m not 100% sure about this solution, but it certainly passes your assertion at the bottom.

]]>