19
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gem の '~> 1.2' みたいなバージョン指定を ['>=', '<'] 表記に展開する

Posted at

gemspec や Gemfile で gem のバージョン番号を指定するときに '~> 1.2' のように書ける (pessimistic version operator とかいうものらしい)

簡潔に書けて便利な反面、簡潔すぎて「'~> 1.2' って上限いくつだよ」といつもわからなくなるのでわかりやすい ['>= 1.2', '< 2'] のような表記に展開する方法を調べた。

Gem::Version#bump で Semantic versioning を意識した「次のバージョン番号」が得られるので、

version = "1.2"
"['>= #{version}', '< #{Gem::Version.create(version).bump}']"

これで ok. テストコードつきのサンプルコードはこちら

オマケ: ブラウザで試せる Gem pessimistic version expander も作った (jsdo.itlleval を利用)


19
17
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
19
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?