Can a ruby gem/module be added just like a java jar file?
I have find the answer to this question. I not sure if this is the best way to do it, but it works for me. Pro developers, can you please review this answer ? So, for now let me give quick guide for this.
1 - Install Eclipse DLTK plugin for Ruby as suggested here - Preferred Ruby plugin for Eclipse?
See the answer with photo, by James.
2 - Next, lets pick a random gem such as nokogiri and download it from rubygems.org. The file name of the Gem tells you which OS its meant for. I use windows 7 64bits. So, I take version with x64-mingw32
. Here is a sample list of downloads:
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. You need to unpack it first. Lets say you kept the gem file in c:\RubyGems\extras, and you want to unpack it there itself.
open windows cmd > cd into the above directory > gem unpack nokogiri-1.6.4.1-x64-mingw32.gem > press enter !!!
Now, your gem will be unpacked into a folder nokogiri-1.6.4.1-x64-mingw32
.
4 - Locate the nokogiri.rb
file inside the unpacked 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 eclipse.
5 - Eclipse > create new ruby project > right click project > build path > configure build path > libraries tab > add external source folder > enter the path from step 4 > Ok > ok. You can now use the gem in your project.
6 - Testing if the steps work. Use the code in your project !
require 'nokogiri'
puts "Chenqui ! It is work!!!"
If the message prints without error, then you are a success ! To see the error you get when the required modules can't be found, add something like this require 'restclient'
.
How does one debug jRuby using eclipse?
Download the Eclipse Dynamic Languages Toolkit - Ruby Development Tools. Import your ruby on rails project. Check that your Gemfile references:
gem 'ruby-debug'
Then go to windows -> preferences, and do two things:
- setting the eclipse ruby interpreter to: c:\jruby\bin\jruby.bat
- setting the eclipse ruby debug engine so it's not the "fast debugger" but "ruby built-in debugger"
Then in the run configuration, main tab, under "ruby script" the launch script is bin/rails
, and in the arguments tab server --debugger
. The interpreter tab should point to JRuby.bat
Go to run -> run and give it about 30 seconds to load the JVM, the ruby environment, and hook everything in. Then check your http://localhost:3000/
To start debug execution then type debugger
in the place you want to start the debugger.
It all starts off looking something like this:
How to debug ruby on rails in eclipse aptana plugin
Issue the following command from the command line:
gem install ruby-debug-ide
The error message is saying that you don't have this gem installed. It seems as though Aptana does not check to see what gems are installed before activating certain features.
In case you don't know what a gem is, think of it as a plugin that is installed system-wide.
How do I create a new ruby project in Eclipse indigo
Please follow the steps below.
Install ruby
Install eclipse (Ex: Eclipse Juno)
Now, install Dynamic Languages Toolkit (DLTK)
- In Eclipse go to Help -> Install New Software
- Click on Add button
- Enter Name as DLTK
- Enter Location as http://download.eclipse.org/technology/dltk/updates/
- Click ok
Select the version and click on Next button
Complete the installation
Enabling Ruby Perspective:
In Eclipse go to Window -> Open Perspective
Select Others..
Select Ruby and click on Ok button
Note: You can save this perspective from Window -> Save Perspective As..
Adding Ruby Interpreter in Eclipse:
In Eclipse goto Window -> Preferences
Select Ruby -> Interpreters
Click on Search button
Select exe and click on Ok button
Hello World:
When above all setup is done correctly you should see Ruby Project in File -> New
Create a new Ruby Project
Add a new class file
Enter puts "Hello World!!"
Click on Ruby Script
You should be able to see Hello World in the console
Happy Ruby learning!!!
Related Topics
Ruby on Rails: Converting "Somewordhere" to "Some Word Here"
Why Does the Rand() Return Always the Same Number
Single Table Inheritance to Refer to a Child Class with Its Own Fields
How to Access a Symbol Hash Key Using a Variable in Ruby
Ruby: Any Gems for Threadpooling
Ruby Class Object Garbage Collection
Ruby Error After Installing Heroku Toolbelt
Webmock Simulate Failing API (No Internet, Timeout ++)
Parsing Xls Spreadsheet in Rails Using Roo Gem
Ruby Outputting to the Same Line as the Previous Output
Require Ruby File Without .Rb Extension
How to Click a Link in a Table Based on the Text in a Row
How to Include Unit Tests in a Ruby Module
Is the Current Ruby Method Called via Super
Ruby How to Merge Two CSV Files with Slightly Different Headers