Class: Chef::Version
- Inherits:
-
Object
- Object
- Chef::Version
- Includes:
- Comparable
- Defined in:
- lib/chef/version_class.rb,
lib/chef/version/platform.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Platform
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#eql?(other) ⇒ Boolean
For hash.
- #hash ⇒ Object
-
#initialize(str = "") ⇒ Version
constructor
A new instance of Version.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(str = "") ⇒ Version
Returns a new instance of Version.
23 24 25 |
# File 'lib/chef/version_class.rb', line 23 def initialize(str = "") parse(str) end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
21 22 23 |
# File 'lib/chef/version_class.rb', line 21 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
21 22 23 |
# File 'lib/chef/version_class.rb', line 21 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
21 22 23 |
# File 'lib/chef/version_class.rb', line 21 def patch @patch end |
Instance Method Details
#<=>(other) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/chef/version_class.rb', line 35 def <=>(other) %i{major minor patch}.each do |method| version = send(method) begin ans = (version <=> other.send(method)) rescue NoMethodError # if the other thing isn't a version object, return nil return nil end return ans unless ans == 0 end 0 end |
#eql?(other) ⇒ Boolean
For hash
55 56 57 |
# File 'lib/chef/version_class.rb', line 55 def eql?(other) other.is_a?(Version) && self == other end |
#hash ⇒ Object
48 49 50 51 52 |
# File 'lib/chef/version_class.rb', line 48 def hash # Didn't put any thought or research into this, probably can be # done better to_s.hash end |
#inspect ⇒ Object
27 28 29 |
# File 'lib/chef/version_class.rb', line 27 def inspect "#{@major}.#{@minor}.#{@patch}" end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/chef/version_class.rb', line 31 def to_s "#{@major}.#{@minor}.#{@patch}" end |