What does tilde-greater-than (~>) mean in Ruby gem dependencies?

jwfearn picture jwfearn · Mar 2, 2011 · Viewed 43.7k times · Source

What does ~> mean in the context of Ruby gem depenedencies?

For example, when opening a legacy project in the RubyMine IDE, I get this message

Gems required for project are not attached:
arel (~> 2.0.2),
rspec-expectation (~> 2.5.0)...

I've seen this tilde-greater-than notation elsewhere in the Ruby world (it's not specific to RubyMine). Does this operator have a name other than the awkward-sounding tilde-greater-than?

Answer

sepp2k picture sepp2k · Mar 2, 2011

It means "equal to or greater than in the last digit", so e.g. ~> 2.3 means "equal to 2.3 or greater than 2.3, but less than 3.0", while ~> 2.3.0 would mean "equal to 2.3.0 or greater than 2.3.0, but less than 2.4.0".

You can pronounce it as "approximately greater than".

§ Pessimistic version constraint