Method: RunLoop::Version.compare

Defined in:
lib/run_loop/version.rb

.compare(a, b) ⇒ Integer

Compare version ‘a` to version `b`.

Examples:

compare Version.new(0.10.0), Version.new(0.9.0)  =>  1
compare Version.new(0.9.0),  Version.new(0.10.0) => -1
compare Version.new(0.9.0),  Version.new(0.9.0)  =>  0

Returns:

  • (Integer)

    an integer ‘(-1, 1)`



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/run_loop/version.rb', line 158

def self.compare(a, b)

  if a.major != b.major
    return a.major > b.major ? 1 : -1
  end

  if a.minor != b.minor
    return a.minor.to_i  > b.minor.to_i ? 1 : -1
  end

  if a.patch != b.patch
    return a.patch.to_i > b.patch.to_i ? 1 : -1
  end

  return -1 if a.pre and (not a.pre_version) and b.pre_version
  return 1 if a.pre_version and b.pre and (not b.pre_version)

  return -1 if a.pre and (not b.pre)
  return 1 if (not a.pre) and b.pre

  return -1 if a.pre_version and (not b.pre_version)
  return 1 if (not a.pre_version) and b.pre_version

  if a.pre_version != b.pre_version
    return a.pre_version.to_i > b.pre_version.to_i ? 1 : -1
  end
  0
end