Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
17
Help us understand the problem. What is going on with this article?

More than 5 years have passed since last update.

@kyanny

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

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 を利用)


17
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
17
Help us understand the problem. What is going on with this article?