From: Steve Tuckner Date: 2002-11-09T01:09:54+09:00 Subject: Re: Beginner Question (Idiomatic way to subset an array I didn't think about the fact that this would generate an a ProcessInfo object but an Array object. It seems that that kind of negates some of the usefulness of select (and possibly other enumerable functions such as reject) when you are sub-classing Array. Why isn't the implementation of select like below? module Enum def select2() a = self.class.new each do |x| if yield(x) then a.push(x) end end a end end class Array include Enum end class A < Array end a = A.new a.push(1) a.push(2) b = a.select2{|x| x == 1} p b ==> [1] print b.class, "\n" ==> A I guess it could be that then it would require any class that includes array to have a constructor that accepts no arguments. Is that too big of a limitation? Are there other ways around this problem? Steve Tuckner -----Original Message----- From: Steve Tuckner [mailto:STUCKNER@MULTITECH.COM] Sent: Friday, November 08, 2002 9:03 AM To: ruby-talk ML Subject: Re: Beginner Question (Idiomatic way to subset an array processInfo.select{|x| process['realm'] == realm} -----Original Message----- From: Booth, Peter [mailto:Peter.Booth@gs.com] Sent: Friday, November 08, 2002 8:51 AM To: ruby-talk ML Subject: Beginner Question (Idiomatic way to subset an array I'm wondering if there is a more idiomatic way to do the following? Can Array.collect be used to extract a subset of an array? Peter Can class ProcessInfo < Array def findByRealm(realm) result = ProcessInfo.new each { |process| if process['realm'] == realm result << process end } return result end end