On 8/3/06, ara.t.howard / noaa.gov <ara.t.howard / noaa.gov> wrote: > On Fri, 4 Aug 2006, Rick DeNatale wrote: > > >> >> "1.8.5" < "1.10.0" > >> => false > > > > Ah, but doing the comparison correctly in Ruby isn't that hard, in a > > few minutes I came up with: > > > > irb(main):023:0> class Version > > irb(main):024:1> include Comparable > > irb(main):025:1> > > irb(main):026:1* def initialize(string) > > irb(main):027:2> @value = string.split('.').collect { | i | i.to_i } > > irb(main):028:2> end > > irb(main):029:1> > > irb(main):030:1* def <=>(another) > > irb(main):031:2> @value <=> another.to_ary > > irb(main):032:2> end > > irb(main):033:1> > > irb(main):034:1* def to_ary > > irb(main):035:2> @value > > irb(main):036:2> end > > irb(main):037:1> end > > => nil > > irb(main):038:0> Version.new("1.8.5") > > => #<Version:0xb7d728e8 @value=[1, 8, 5]> > > irb(main):039:0> Version.new("1.8.5") < Version.new("1.10.0") > > => true > > > > I'd strongly suggest, that it's much better for Ruby if it tries to > > stay in line as much as possible with how things are done in the open > > source community. > > > > There's a lot of software outside of Ruby which depends on having > > versions being a tuple of numbers. Since Ruby makes it easy to meet > > things like that more than halfway, I think that it's better to do so. > > but this isn't correct by 'open source' standards > > http://codeforpeople.com/lib/ruby/library/library-0.0.0/doc/ > http://sources.redhat.com/autobook/autobook/autobook_91.html > > in order to compare you have to consider the semantics of each positional > number I'm not sure I see the point. Each level has less signficance than the one before. I'm pretty sure that's how the code I posted orders versions. -- Rick DeNatale IPMS/USA Region 12 Coordinator http://ipmsr12.denhaven2.com/ Visit the Project Mercury Wiki Site http://www.mercuryspacecraft.com/