Reputation: 997
I have just started learning ruby . There are few things I am quite confuse with in ruby as I used to work with Perl and C.
1) How to add external library like "Mechanize" to use with your script?
Upvotes: 0
Views: 153
Reputation: 211560
Ruby has virtually standardized on using bundler to manage dependencies. For any project you create a Gemfile
that looks roughly like:
source 'https://rubygems.org/'
gem 'mechanize'
Then you would run bundle install
to be sure your gems are loaded correctly.
Inside your application you'd have:
require 'rubygems'
require 'bundler/setup'
require 'mechanize'
# ...
If you want to build your own gem, the best thing to do is read the documentation and look at the source of other gems to see how they do it. Every gem has to follow certain conventions to work correctly, but these are pretty obvious if you look at more than a few of them.
You can even use bundler to help build a new gem which can simplify the process considerably.
Upvotes: 1