LoginSignup
4
4

More than 5 years have passed since last update.

Rails系のgemのversion.rbが独特だった話

Last updated at Posted at 2016-03-31

独特かどうかはわかりませんが、、、

僕はこんなことしなかったし考えもしなかったなと。

まず、gemを作るときはversion.rbというファイルにversionを書きます。
そしてgemspecでそれを読むわけですが、
普通はこれくらいかなと。

Hogeというgemを作ると仮定して、

# hoge/version.rb
module Hoge
  VERSION = "1.0.0".freeze
end

しかし、rails系(actionxxxxやactivesupportなどは)

# active_support/version.rb
module ActiveSupport
  # Returns the version of the currently loaded ActiveSupport as a <tt>Gem::Version</tt>
  def self.version
    gem_version
  end
end

# active_support/gem_version.rb
module ActiveSupport
  # Returns the version of the currently loaded Active Support as a <tt>Gem::Version</tt>.
  def self.gem_version
    Gem::Version.new VERSION::STRING
  end

  module VERSION
    MAJOR = 5
    MINOR = 0
    TINY  = 0
    PRE   = "beta3"

    STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
  end
end

gem_version.rbを定義し、そこで管理している。
そこまでやる必要があるのかが正直わからないが、かっこいいなとだけ思いました。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4