On 10 Oct 2007, at 14:06, PeƱa, Botp wrote:
e==2 ⦠in fact, i find #in? so genericā¦
or maybe you want a keyword only like msbasicās
e in a2
?
kind regards -botp
If I understand you correctly the :in? method would have to be
defined in Object (so that all Objects could be tested). So something
like:
irb(main):001:0> class Object
irb(main):002:1> def in?(enum)
irb(main):003:2> enum.include?(self)
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> 1.in? [1,2,3]
=> true
irb(main):007:0> 4.in? [1,2,3]
=> false
Danielās point (I think) is that this pollutes the top level Object
with a property which for many (most?) Objects is never relevant. If
you never put it an Object into a collection then the idea of being
āinā something makes no sense.
On the other hand it is always an intrinsic part of an Enumerable
implementing class (by definition a collection of Objects) that you
may often need to know whether it āincludesā a specified object.
Iām not sure why the includes construct rocks your brain though. Both
read very logically to me (as a native English speaker admittedly):
a3 = a1.select { |e| a2.include?(e) }
reads as: āselectā from a1 those e where a2 āincludesā e.
a3 = a1.select { |e| e.in? a2}
reads as: āselectā from a1 those e where e is āinā a2.
That said I always write this as:
a3 = a1 & a2
Alex G.
Bioinformatics Center
Kyoto University