From: Ilias Lazaridis Date: 2011-06-06T17:15:35+09:00 Subject: Re: CORE - Altering Behaviour of "each do" (default param "item") On 6 Ιούν, 10:14, Robert Klemme wrote: > 2011/6/5 Ilias Lazaridis > > > > > > > > > > > > > On 4 Éïýí, 21:02, Robert Klemme wrote: > > [...] > > > There is another approach which does not suffer from the side effect of > > [...] > > > Note to readers: > > > This approach is not usable in the given context (Altering Behaviours > > of "each do"). > > > The code can *possibly* altered, thus it works on Array#each. > > > For a solution which works exactly in the given context (Array#each), > > see message from "James Gray" below (you can ignore all following > > messages, they are off-topic). > > If you look close enough you will notice that *both* approaches work > (or don't) the same way with regard to #each - for the same reason! I don't have to "look close enough" This was the original context (specification): 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 The specification is very simple. Your solution does not work in this context. The solution from Gray works 100%. If you like, you can still modify your solution to pass the specification. If not, feel free to setup a new context (specification), but please use a new topic. . -- http://lazaridis.com