From: Mike Fletcher Date: 2006-08-04T00:21:12+09:00 Subject: Re: A left-exclusive Range class Brian Guthrie wrote: > Cyrus Hall wrote: >> have been a related debate about this on ruby-talk back in Oct. 2004, >> with the conclusion being, to paraphrase the entire discussion, "this is >> hard, lets forget about it for now." >> >> Has this been discussed since 2004? Would people be interested in >> finding a way to get left-exclusion into the Range class? This may be >> something that has been addressed in all the language work going into >> 1.9/2.0, and if so, any pointers would be greatly appreciated. Doesn't preserve the fact that it started as a left exclusive range, but how about: class Range alias :orig_initialize :initialize def initialize( s, e, exclusive=false ) case exclusive when false, true orig_initialize( s, e, exclusive ) when :left orig_initialize( s.succ, e ) when :right orig_initialize( s, e, true ) when :both orig_initialize( s.succ, e, true ) end end end Then you can do Range.new( 1, 5, :left ) or Range.new( 1, 5, :right ) or use the .. / ... operators as well. -- Posted via http://www.ruby-forum.com/.