Introduce Rails.gem_version#14101
Conversation
|
/cc @jeremy |
|
Excuse me if I'm wrong but existing libraries are relying on |
Ah sorry, missed that part. Thanks for the explanation. |
|
This also changes each framework's |
|
@jeremy Then what should we do with partially-introduced |
There was a problem hiding this comment.
Introduces -> Introduce
returns -> return
We say it's useful for performing version comparison. Let's show an example. A good one is how Rails.version > '4.1.10' would be true for '4.1.2' also due to lexicographic string comparison, but would be false when comparing gem versions.
Unfortunately you can't do Rails.gem_version > '4.1.10'. You have to:
if Rails.gem_version > Gem::Version.new('4.1.10')
# ...and that's limited to exact version comparison. Pretty verbose and hard to discover.
Furthermore, to do more realistic version requirement checks, you'd use:
if Gem::Requirement.create('~> 4.1.2') =~ Rails.gem_version
...Which you'd need some digging in RubyGems docs to even figure out.
All told, we may be better off just saying: "Introduce Rails.gem_version as a convenience method to return Gem::Version.new(Rails.version)".
It's not something most app developers would ever touch, so suggesting it's useful is a stretch, but plugin developers may take note and use it.
There was a problem hiding this comment.
"suggesting more" -> "suggesting a more"
This method return `Gem::Version.new(Rails.version)`, suggesting a more
reliable way to perform version comparison.
Example:
Rails.version #=> "4.1.2"
Rails.gem_version #=> #<Gem::Version "4.1.2">
Rails.version > "4.1.10" #=> false
Rails.gem_version > Gem::Version.new("4.1.10") #=> true
Gem::Requirement.new("~> 4.1.2") =~ Rails.gem_version #=> true
This was originally introduced as `.version` by @charliesome in rails#8501
but got reverted in rails#10002 since it was not backward compatible.
Also, updating template for `rake update_versions`.
This method returns a
Gem::Versionobject, which is useful when performing a comparison between versions. This was originally introduced as.versionby @charliesome in #8501, but got reverted in#10002 since it was not backward compatible.
Also, updating template for
rake update_versions.