Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Ruby libraries and gems with a Shoes app

I am writing a little Shoes app that requires a library I wrote with my regular Ruby installation. My library uses the 'net-ssh' gem and a bunch of other Ruby libraries.

When I run my library directly with regular ruby (it has its own command-line interface) like this:

ruby my_lib.rb

...all is fine. But when I try to require it within my Shoes app I get an 'no such file to load - net/ssh' error (because my_lib uses net-ssh).

I tried messing around with the $: include path variable in the Shoes app like this:

$:.unshift "C:/ruby/lib/ruby/1.8"
$:.unshift "C:/ruby/lib/ruby/site_ruby/1.8"
require 'rubygems'
gem 'net-ssh'
require 'my_lib.rb'

...but had no success. I get 'Could not find RubyGem net-ssh'.

Anyone has had the same problem? What's the best way to use your Ruby libraries and gems in a Shoes app?

like image 299
Dema Avatar asked Feb 04 '09 17:02

Dema


People also ask

Are Ruby Gems libraries?

RubyGems is a Ruby packaging system designed to facilitate the creation, sharing and installation of libraries (in some ways, it is a distribution packaging system similar to, say, apt-get , but targeted at Ruby software).

What is Library Ruby?

Ruby on Rails Gems is a package manager containing libraries, software packages, and utilities for standard format distribution of Ruby programs and libraries. RoR Gems have functionality with related files to help save time in web development.

Is a gem a library?

In Ruby, a gem is a library that contains a specific piece of functionality as well as any files or assets related to that functionality.


1 Answers

Hey, _why posted on his blog, hackety.org, about using gems within Shoes. I hope it helps!

Shoes.setup do
  gem 'json >= 1.1.1'
  gem 'activerecord'
end

require 'json'
require 'activerecord'

Shoes.app do
  @msg = para "ALL SYSTEMS GO"
  animate(20) { @msg.toggle }
end
like image 80
baxter Avatar answered Sep 20 '22 01:09

baxter