From: "David A. Black" Date: 2005-09-26T23:11:08+09:00 Subject: Re: How each class splats Hi -- On Mon, 26 Sep 2005, Trans wrote: > First I'll just ask it there's a way to do this WITHOUT redefining > #each in Array. > > class A > def initialize(i,v) > @i,@v=i,v > end > end > > arrayofA = [ A.new(:a,1), A.new(:b,2) ] > > arrayofA.each { |e| p e } > => # > # > > arrayofA.each { |i,v| p i,v } > => :a > 1 > :b > 2 You could probably get a similar result by doing something with A#inspect, though probably not exactly what you've got here. > If thsi is not possible, what do people think of allowing a class to > define a #splat method to determine how it will splat into an each > block (and perhaps other things). I'd want a better name, and more rationale. My instinct is to prefer to know how scalar and/or container objects will behave, and plan for that, rather than have different objects do arbitrarily different things in the face of argument assignment. David -- David A. Black dblack@wobblini.net