Class: Hashie::Extensions::RubyVersion
- Inherits:
-
Object
- Object
- Hashie::Extensions::RubyVersion
- Includes:
- Comparable
- Defined in:
- lib/hashie/extensions/ruby_version.rb
Instance Attribute Summary collapse
-
#segments ⇒ Object
Returns the value of attribute segments.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(version) ⇒ RubyVersion
constructor
A new instance of RubyVersion.
Constructor Details
#initialize(version) ⇒ RubyVersion
Returns a new instance of RubyVersion.
22 23 24 |
# File 'lib/hashie/extensions/ruby_version.rb', line 22 def initialize(version) @segments = split_to_segments(version) end |
Instance Attribute Details
#segments ⇒ Object
Returns the value of attribute segments.
20 21 22 |
# File 'lib/hashie/extensions/ruby_version.rb', line 20 def segments @segments end |
Instance Method Details
#<=>(other) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/hashie/extensions/ruby_version.rb', line 26 def <=>(other) lhsegments = segments rhsegments = other.segments lhsize = lhsegments.size rhsize = rhsegments.size limit = (lhsize > rhsize ? lhsize : rhsize) - 1 i = 0 while i <= limit lhs = lhsegments[i] || 0 rhs = rhsegments[i] || 0 i += 1 next if lhs == rhs return -1 if lhs.is_a?(String) && rhs.is_a?(Numeric) return 1 if lhs.is_a?(Numeric) && rhs.is_a?(String) return lhs <=> rhs end 0 end |