General Question

VoodooLogic's avatar

How do I employ a ruby gem?

Asked by VoodooLogic (729points) May 31st, 2010

I want to build a simple twitter app using Ruby on Rails. I installed the (twitter) gem and cannot figure out how to employ it. For any gem for that matter… is it supposed to work right out of the box?

Observing members: 0 Composing members: 0

8 Answers

jrpowell's avatar

Use in this in the Terminal or SSH to check that the gem installed correctly.
gem list—both
That should be two separate dashes, Fluther is screwing up and combining them both.

From there you should just be able to call when you need to use it.

require ‘rubygems’
require ‘NAME OF GEM’

Use straight quotes not curly ones. Fluther mangles these too.

jrpowell's avatar

And depending on what you plan to do using rails might be like putting in a finishing nail with a sledgehammer. For simple stuff I would us Sinatra. It is a hell of a lot faster and easier.

gailcalled's avatar

Not a jewelry question, I guess.

VoodooLogic's avatar

@gailcalled LOL! No, but your comment made me smile.

VoodooLogic's avatar

@johnpowell trying to get over the learning curve of RoR by making my own twitter application. I’m using the twitter gem and OAuth. Well, I’m trying to. Plugins seem to be generic enough so that you have to know what your doing to employ them. Right now I’m hunting down examples that I can learn from. If anyone else reads this after me, I’ve had success with the twitter-auth gem but none yet with twitter. Although I did just find an example for the latter.

sferik's avatar

@VoodooLogic I’m one of the maintainers of the Twitter gem and would be happy to answer any specific questions you have while writing your Twitter application.

To start, I would recommend reading the Beginner’s Guide to OAuth, since accessing most of the Twitter API requires authentication.

Once you understand OAuth, I’d recommend browsing the examples that are included with the gem.

Here’s one of my favorite Twitter gem one-liners that doesn’t require OAuth, courtesy of Patrick Ewing (you must first require the gem, as described in @johnpowell‘s answer):

puts Twitter::Search.new(“marry me”).to(“justinbieber”).collect{|tweet| tweet.text}

I would also refer you to two Google Groups. First, the group for the gem, which contains answers to many previously-asked questions about getting started. The second is Twitter API Announcements, which contains important announcements about changes to the API.

VoodooLogic's avatar

I’ll be reading that article shortly. I’m now pretty familiar with using the Twitter::Search class in the console – fun times, btw – and I’ve read up on the twitter API. I can’t wait to start building some custom methods.

Thanks for the reply and thanks again for the gem!!!!

VoodooLogic's avatar

A big part of the problem was my environment.rb had a boilerplate line that should have been set to:
ENV[‘GEM_PATH’] = ’/home2/akamados/ruby/.gems:/usr/lib/ruby/gems/1.8’
I changed the line to the above and did a gem list—local and found I didn’t have ANY gems installed.
Once I reinstalled the gems I needed, my app stopped breaking and life is good.

howtos and tutorials are almost non-existent (hard to find) on my host.

I’ll do my part and blog about it.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther