In Python I can install a package from source in "editable" mode using pip install -e
. Then I can carry on editing the code, and any changes will be automatically picked by other Python scripts that import library
Is there a comparable workflow for developing Ruby gems? What is the "Ruby way" of using libs as they are being developed rather than, for example, compiling and installing a gem every time I make a change to the source?
pip install -e . This will install the current package in your Python environment in an editable mode. You can keep changing this package at its source directory and your changes will be immediately reflected in your environment.
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.
Ruby comes with RubyGems by default since version 1.9, previous Ruby versions require RubyGems to be installed by hand.
Open up the 'Software Center' app from your launcher and type in `RubyGems` without quotes into the application search box at the top right, and press [enter]. RubyGems then can be installed by just clicking on the button labeled 'Install', thats it.
There are two common approaches one might use with bundler
:
bundle install --path vendor/bundle
and does not run bundle update
unless everything is tested.Gemfile
(this is not supported in mymaingem.gemspec
due to rubygems maintainence issues): gem 'mycutegem', :git => 'git://github.com/myname/mycutegem', :branch => 'master'
;bundle config local.mycutegem /path_to_local_git/mycutegem
.The first approach will download everything into subfolder of your current project (here it’d be vendor/bundle
.) Feel free to modify everything there, it’ll be reflected.
The second approach is likely better. You are to clone the gem from github and instruct bundle
to use your local clone of the respective git repository. This approach provides you with an ability to publish the changes to your main gem into the repository. As soon as dependent repo is published as well, the up-to-date version will be retrieven by your gem subscribers, assuming they have not instructed their bundler
s to use their locals.
Hope this helps.
Let's assume you have your gem code residing in a folder (say my_project/mygem/lib
). You have some Ruby code in my_project
that you want using the mygem
code.
What I'd do is add mygem/lib
to the $LOAD_PATH
global variable in the beginning of said files. Kinda like this:
$LOAD_PATH << File.expand_path('lib', './mygem') # Resolve global paths
require 'a_file' # Would require "mygem/lib/a_file.rb"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With