Class: Jison::Version
- Inherits:
-
Object
- Object
- Jison::Version
- Includes:
- Comparable
- Defined in:
- lib/jison/version.rb
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#micro ⇒ Object
readonly
Returns the value of attribute micro.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(major, minor = 0, micro = 0) ⇒ Version
constructor
A new instance of Version.
- #to_s ⇒ Object
Constructor Details
#initialize(major, minor = 0, micro = 0) ⇒ Version
Returns a new instance of Version.
12 13 14 |
# File 'lib/jison/version.rb', line 12 def initialize(major, minor=0, micro=0) @major, @minor, @micro = major, minor, micro end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
5 6 7 |
# File 'lib/jison/version.rb', line 5 def major @major end |
#micro ⇒ Object (readonly)
Returns the value of attribute micro.
5 6 7 |
# File 'lib/jison/version.rb', line 5 def micro @micro end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
5 6 7 |
# File 'lib/jison/version.rb', line 5 def minor @minor end |
Class Method Details
.from_string(string) ⇒ Object
7 8 9 10 |
# File 'lib/jison/version.rb', line 7 def self.from_string(string) version = string.gsub(/^\s+|\s+$/, '').split('.').map(&:to_i) new(*version) end |
Instance Method Details
#<=>(other) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jison/version.rb', line 22 def <=>(other) case other when Version cmp = major - other.major return cmp unless cmp.zero? cmp = minor - other.minor return cmp unless cmp.zero? micro - other.micro when String self <=> Version.from_string(other) when Fixnum major - other else raise RuntimeError.new("Cannot compare against #{other.class}: #{other.inspect}") end end |
#==(other) ⇒ Object
16 17 18 19 20 |
# File 'lib/jison/version.rb', line 16 def ==(other) major == other.major \ && minor == other.minor \ && micro == other.micro end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/jison/version.rb', line 39 def to_s "#{major}.#{minor}.#{micro}" end |