From: Panagiotis Atmatzidis Date: 2011-06-05T00:17:34+09:00 Subject: Re: CORE - Altering Behaviour of "each do" (default param "item") go it... On 04 Ιουν 2011, at 5:50 μ.μ., James Gray wrote: > On Sat, Jun 4, 2011 at 6:50 AM, Ilias Lazaridis wrote: > >> 1.9 >> >> names = ["Jane", "Michele", "Isabella"] >> >> # current behaviour >> names.each do |name| >> print name >> end >> >> #Question: How can I alter the behaviour of "each" in the following >> way: >> names.each do >> print item # "item" is used by default >> end >> >> Is this possible, without going to C-level? >> > > Since everyone is still speaking to Ilias far too often, I'll try to use > this as a teaching experiment. I'll post the code that does exactly what he > asked for. Exactly. If he follows standard form, you should see complaints > about the non-code content of this message and the solution itself. > > The solution: > > ####################################################### > ### NEVER USE THIS CODE, unless your name is Ilias! ### > ####################################################### > > class Item > def initialize(item) > @item = item > end > > attr_reader :item > end > > class Array > alias_method :sane_each, :each > def each(&iterator) > if iterator.arity.zero? > sane_each do |item| > Item.new(item).instance_eval(&iterator) > end > else > sane_each(&iterator) > end > end > end > > names = %w[Jane Michele Isabella] > > names.each do |name| > puts name > end > > names.each do > puts item > end > > __END__ > > The most important thing to learn about Ilias is that he's not a programmer > and has no desire to become one. Ever. Look at his code from this example. > Ilias never posts project code. He doesn't do anything. He just attacks > esoteric corners of syntax to incite debate. > > His requests almost always involve terrible ideas that obviously violate > some good programming practice. If he doesn't know this, he has never > learned it from all the years he has spent in many programming language > groups. If he does know it, he's using his knowledge optimally to push the > most buttons. Either way, you know what you need to know. > > Note how he's never learned the tiniest bit of Ruby during any of his stays > with us. He doesn't indent like we do, he wouldn't think to call puts(), > etc. Ilias literally cannot assimilate, beyond minor efforts to gain > sympathizers. > > See his other messages for examples of how he usually selects the most > abrasive language. Words like "BARRIER" are used for a desired effect and > he loves it when we tell him not to talk to us that way. > > You all know that I try very hard to be polite and helpful. Ilias is the > exception. I totally believe he is diagnosable. Anytime we push "Reply," > we feed his needs. It's hard, but you really have to ignore him. It's the > only option he leaves to us. > > You won't see me respond when he complains about this message. He'll say > stupid things I'm dying to correct for all the watching eyes. That's what > Ilias does. Though it hurts me, I won't push "Reply." Just writing a > message like this about a person kill's me. But these are the only ways to > minimize his reach. We are not playing this game against a rational > opponent. > > Choose another soul to save on Ruby Talk and let this one go. > > http://www.nationmaster.com/encyclopedia/Ilias-Lazaridis > > James Edward Gray II -- Panagiotis Atmatzidis email: ml@convalesco.org blog: http://www.convalesco.org The wise man said: "Never argue with an idiot. They bring you down to their level and beat you with experience."