Is it possible to add a ruby ​​pearl / module just like a java jar file?

I am using Eclispse Kepler with DLTK plugin for ruby. I cannot "require" the nokogiri module because it cannot be found by eclipse. I tried some gem install command from some website and it didn't help. Now I don't want to use the command line until I start programming Ruby first.

I found out that I can add java jars to my project by creating a lib folder, copying the jars to that folder and then adding them all to the build path. So easy, isn't it?

Can I do the same for ruby ​​gems and modules? Ideally I would like to only use the IDE for this instead of using command line scripting and add-ons.

Please, help.

+3


source to share


4 answers


I found the answer to this question. I'm not sure if this is the best way to do it, but it works for me. Pro, can you view this answer? So now let me give you a quick guide to doing this.

1 - Install Eclipse DLTK plugin for Ruby as suggested here - Preferred Ruby plugin for Eclipse? See answer with photo by James.

2 - Next, let's pick a random gem like nokogiri and download it from rubygems.org. The Gem filename indicates which OS it is for. I am using Windows 7 64 bit. So, I accept the c x64-mingw32

. Here's a sample download list:

1.6.4.1 November 7, 2014 java (2.37 MB)
1.6.4.1 November 7, 2014 x64-mingw32 (2.86 MB)
1.6.4.1 November 7, 2014 (8.81 MB)
1.6.4.1 November 7, 2014 x86-mingw32 (3.91 MB)
1.6.4 November 5, 2014 java (2.37 MB)
Show all versions (271 total)

      

3 - AFAIK, eclipse cannot use the gem file as is. First you need to unzip it. Let's say you saved the gem file in c: \ RubyGems \ extras and you want to unpack it there yourself.

open windows cmd> cd to the above directory> gem unpack nokogiri-1.6.4.1-x64-mingw32.gem> press enter !!!



Your stone will now be unpacked into a folder nokogiri-1.6.4.1-x64-mingw32

.

4 - Find the file nokogiri.rb

inside the unzipped folder. Its in the lib folder. Copy the full path of this folder - c:\RubyGems\extras\nokogiri-1.6.4.1-x64-mingw32\lib

. We need this for the eclipse.

5 - Eclipse> create a new ruby ​​project> right click project> build path> customize build path> libraries tab> add external source folder> enter path from step 4> Ok> ok. You can now use the gem in your project.

6 - Testing if steps work. Use the code in your project!

require 'nokogiri'

puts "Chenqui ! It is work!!!"

      

If the message prints without errors, then you are successful! To see the error you get when the required modules cannot be found add something like this require 'restclient'

.

0


source


If this gem is already installed with all dependencies, you can add it with a simple command require

:

require "/ path_to_gems / gem_name / lib / gem_name"

In my case, the command:



require '/Users/yukke/.rvm/gems/ruby-2.1.1/gems/nokogiri-1.6.1/lib/nokogiri'

Otherwise, you can first require rubygems

:

require "rubygems"
require "gem-name"
+4


source


I would suggest perhaps using another IDE with better Ruby support, like Aptana , which is based on Eclipse but has many additional add-ons to support Ruby development. You can install Ruby stones on it from the start page or via the built-in terminal.

+2


source


If you run the command gem which bundler

, you will see gems installed on your system. You can copy the executables there, but it is highly recommended to use gem install on the command line.

+1


source







All Articles