Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I declare gemspec dependency as >= 3.1 but less than < 4.0

I am making changes to my ruby gem to make it asset pipeline compatible. In my gemspec I want to say that it requires rails version > 3.1 and < 4. How do I do that.

currently this is what I have.

s.add_dependency("rails", ">= 3.1")

But this is not ideal. This is saying that it will also work with rails 4.0 which might not be true.

like image 864
Nick Vanderbilt Avatar asked Mar 15 '12 08:03

Nick Vanderbilt


People also ask

How do I install a specific version of a gem?

Use `gem install -v` You may already be familiar with gem install , but if you add the -v flag, you can specify the version of the gem to install. Using -v you can specify an exact version or use version comparators.

What is Gemspec in Gemfile?

Gemspec is basically the Readme for gems. It tells you about the author, version, summary, description, internal dependencies, execution and everything about the Gem. So now it was easy to use gems as all of them were having their specifications with them.

What are gem dependencies?

development. RubyGems provides two main “types” of dependencies: runtime and development. Runtime dependencies are what your gem needs to work (such as rails needing activesupport). Development dependencies are useful for when someone wants to make modifications to your gem.


1 Answers

You can use the pessimistic operator ~>

Using the pessimistic operator, you could write

s.add_dependency("rails", "~> 3.1")

which is equivalent to '>= 3.1', '< 4.0'

like image 121
Andrei S Avatar answered Oct 21 '22 23:10

Andrei S