--1926193751-817947877-12154832139667 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-817947877-1215483213=:29667" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-817947877-12154832139667 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Tue, 8 Jul 2008, Yossef Mendelssohn wrote: > > > On Jul 7, 1:32 am, Sandor Szs <sandor.szu... / fu-berlin.de> wrote: >> class Array >> alias old_include? include? >> def include?(*args) >> >> if args.length <= 1 >> old_include?(args) >> else >> args.all? do |a| >> old_include?(a) >> end >> end >> end >> end >> >> puts("#{(0..9).to_a.include?(3,5)}") # true >> puts("#{('a'..'z').to_a.include?(3,5)}") # false >> puts("#{('A'..'ZZ').to_a.include?('G','AB')}")# true >> >> regards, Sandor Szs >> -- > > Two things: > > 1) This doesn't work. Try ('a'..'z').to_a.include?('a') > 2) The length check isn't necessary. It's sufficient to just use > args.all? { |a| old_include?(a) }, assuming it's okay that calling > include? with no arguments now returns true. I'd be in favor of keeping that safeguard, partly because it feels weird for [1,2,3].include?() to be true and partly because there might be some edge case or test where having it succeed silently might be problematic. A case statement might be a nice way to handle it: def include?(*args) case args.size when 0 old_include? else args.all? {|a| old_include?(a) } end end I also think this one is kind of cool, though I would assume it's a good bit slower: def include?(head,*tail) case tail when [] old_include?(head) else include?(head) && include?(*tail) end end David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails July 21-24 Edison, NJ Advancing With Rails August 18-21 Edison, NJ See http://www.rubypal.com for details and updates! --1926193751-817947877-12154832139667-- --1926193751-817947877-12154832139667--