Class: Opal::Version

Inherits:
Object show all
Defined in:
lib/opal.rb

Overview

This is Version. Opal uses it for it’s non-Float Version.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major, minor, build, revision) ⇒ Version

Create a new Version.



156
157
158
# File 'lib/opal.rb', line 156

def initialize(major, minor, build, revision)
	@arr = [major, minor, build, revision]
end

Instance Attribute Details

#arrObject

Returns the value of attribute arr.



153
154
155
# File 'lib/opal.rb', line 153

def arr
  @arr
end

Instance Method Details

#+(v) ⇒ Object

Add two versions.

Raises:

  • (ArgumentError)


161
162
163
164
# File 'lib/opal.rb', line 161

def +(v)
	raise ArgumentError unless v.class == Version
	(0..3).to_a.each { |t| @arr[t] += v.arr[t] }
end

#inc!Object

Increment the version by one.



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/opal.rb', line 167

def inc!
	@arr[3] += 1
	if @arr[3] == 10
		@arr[3] = 0
		@arr[2] += 1
		if @arr[2] == 10
			@arr[2] = 0
			@arr[1] += 1
			if @arr[1] == 10
				@arr[1] = 0
				@arr[0] += 1
			end
		end
	end
	return self
end

#inspectObject Also known as: to_s

Inspect the object.



185
186
187
# File 'lib/opal.rb', line 185

def inspect
	@arr.join "."
end