Why can't Shoes::Setup#gem find my gem? - ruby

Despite reading what has been written on this here and here and here, I still can't get these lines to work for me:
Shoes.setup do
gem 'statemachine'
end
require 'rubygems'
require 'statemachine'
I have run "sudo gem install statemachine" successfully and copied the gem by hand to ~/.shoes/ to no avail so far.
I am using ruby 1.8 under Mac OS X 10.5.8 and the gem I'm trying to use has no dependencies and works perfectly when invoked from Ruby.
I am trying to grok the Shoes and Gem code to solve this mystery but could use some help from experienced programmers.
Thanks.

That code works fine for me. Shoes should go out on its own and get the gem if needed. Your problem may be that you copied the gem over. Try deleting it from ~/.shoes/ and running the code again.

Related

unable to run a gem through terminal

I uploaded my first gem into rubygems. The code is tested and the gemspec is fine. It is in rubygems and rubydoc. I installed it on my machine via gem install [gem_name]. gem list lists it. However [gem_name] command yields gem_name: command not found.
YET: gem '[gem_name]','~>[version_num]' yields: ERROR: While executing gem ... (Gem::CommandLineError)
Unknown command gem_name,~>version_num
(aside: I could've sworn when I first published I played with it and gem_name worked flawlessly to run my gem...)
what can I do to diagnose this problem? Please advise.
EDIT: require '[gem_name]' works flawlessly in IRB. It runs smoothly (interacts with user). Once finished, it returns true. When I require other gems, eg require '[another_gem]' true is returned immediately. The code doesn't actually run. Perhaps this shed some light?
gem gem_name or gem_name is not a command. If you are trying to check if the gem installed properly, try gem_name -v. Also, depends on what flags and args your gem takes.
You are getting that error becausegem gem_name is not a command.
For eg: You do a gem install rails. Then you don't just do gem rails to run it. You do rails some_command or flag, etc. Like rails new blog.
Do other gems run properly? If not, the issue may be with your path. If you run the gem from the folder it is located in, does it still yield problems? Hope this helps!

How do I install openssl for Ruby 1.9.3

This is driving me crazy. Endless google searches yield zero help for what should be a simple task. I have a ruby script that requires the 'openssl' library, a script that was previously working before I upgraded my Ruby build to 2.2.2. This messed all my existing ruby stuff up, so I rolled back to my original version of 1.9.3, and openssl is now gone. I tried
gem install 'openssl'
and a bunch of other variations, but this simply throws the error
ERROR: Could not find a valid gem 'openssl' in any repository
Can anybody tell me how I can get openssl back in my Ruby installation?
I suggest trying ruby-build, which is a ruby installer.
Even if you don't plan to use it long-term, it's good about installing all the dependencies, such as SSL. If ruby-build succeeds for you, then you can look at its logs to see how it succeeded.
Ok, so my question was a silly one that didn't even make sense. Openssl wasn't the problem, and I was able to fix my own issue. If an admin could close or even delete this thread, that would probably be best for everybody.

What is the easyest way to use gems in a macruby application, in XCode?

I need to include a rubygem in a simple macruby application i am creating in XCode. Using require 'rubygems' does not give an error, but the next line to require any other gems has a load error. I installed the gems using macgems. Thanks in advance.
The load error might be an indication that the gem doesn't work on Macruby. Post the error and someone might have more info on that gem or that error.
Did the gem actually install correctly? If it did install, does it work from the command line? Try creating a simple script that requires rubygems and your gem and run that on the command line outside of xcode and see if the problem is compatibility with that gem.
A while back in the 0.5 days I had this problem with a gem (miniexif iirc) that would install via macgems but not load or run. This might be a similar problem.

Sinatra doesn't load when running a ruby app

I'm trying to run a Ruby application that requires Sinatra within Ubuntu 10.10. I'm new to the 3 of these technologies so I understand if this question looks dumb to you.
Yesterday I installed ruby doing...
sudo apt-get install ruby1.9.1-full
And sinatra by doing...
sudo gem install sinatra
This is the code I'm trying to run:
require 'rubygems'
require 'sinatra'
get '/' do
"Hi Alex!"
end
When I do ruby1.9.1 -rubygems app.rb nothing happens (Ruby is properly installed since I tried running apps that don't require sinatra and they work OK).
$ ls
app.rb
$
$ ruby1.9.1 app.rb
$
$ ruby1.9.1 -rubygems app.rb
$
I know it should open Sinatra and tell me which port it is listening to.
I've been looking for help through the web and read several of the threads created within this forum but nothing I've tried has worked out for me.
What could be happening here?
Thanks
There was a similar problem with sinatra 1.0 on ruby 1.9.2. The answer there was to add enable :run to your code.
Have a look at the docs for the :run configuration - if you're going to be deploying to a server you'll want to do something like enable :run if __FILE__ == $0 so that you only start the built-in server during development when you need it.
Strictly speaking your code is correct and should run okay, and in fact it does with ruby 1.8.7 and 1.9.2. The problem seems to be running it with ruby 1.9.1. In general 1.9.1 seems to be fairly outdated and you should probably look to upgrade to 1.9.2 if you can. If Ubuntu doesn't have any packages for 1.9.2 take a look at rvm. (In fact if you're going to be doing ruby development rvm is worth a look anyway).
Update:
I managed to get ruby 1.9.1 compiled to test this, and your code worked ok. Also a bit of googling suggests that the Ubuntu ruby1.9.1 package provides ruby 1.9.2 anyway. So there seems to be something else going on causing :run not to be set when running the file directly, though I don't know what that could be.
Another update:
Looking at the Ubuntu Sinatra package it looks like it's at version 1.0. It could be that your setup is using the Ubuntu
package and ignoring the more recent version installed via rubygems. This could explain what's happening. If so this isn't a "a similar problem" to ruby 1.9 and sinatra 1.0 like I suggested above, it's the same problem!
Yet another update:
A couple of things have occurred to me. You can check what version of Sinatra you're actually using with something like puts Sinatra::VERSION after require 'sinatra'. Also, it looks like there is a gem1.9.1 command that corresponds to ruby1.9.1. It looks like when you installed sinatra with sudo gem install sinatra the latest version got installed into the ruby 1.8 install, and left ruby 1.9 with the Ubuntu packaged Sinatra 1.0. If you haven't switched over to rvm yet, you could try sudo gem1.9.1 install sinatra.

Ruby Twitter gem

-- UPDATE --
Ok its fixed. This is what I did. remove all ruby and rubygems completely. then install ruby1.9.1-full and rubygems1.9.1 then install the twitter gem.
Hi guys,
I am having trouble working with the Twitter gem. I am using ruby 1.8.7
After installing when I try to run a simple script I get this error
ruby twitter.rb
./twitter.rb:5: uninitialized constant Twitter (NameError)
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from twitter.rb:2
I running this on a Ubuntu box. I checked with gem -list and I see the Twitter (1.1.0) is listed there.
this is the code I am trying to run
require "rubygems"
require 'twitter'
puts Twitter.user_timeline("test").first.text
Any ideas ?
I believe it only works with Ruby 1.9 If you want to use twitter gem try version 0.9 with Ruby 1.8.x
This works for me:
ruby-1.9.2-p0 > require 'twitter'
=> true
ruby-1.9.2-p0 > puts Twitter.user_timeline("test").first.text
TExES Pedagogy and Professional Responsibilities EC-12 Teacher Certification Test Prep Study Guid… - by Sharon A Wynne http://amzn.to/f3kF74
=> nil
which version of ruby are you using?
gouravtiwari21's comment seems to fix the problem, but it's wrong to suggest that the twitter gem requires 0.9.0 if you want to run it using Ruby 1.8.x.
You can check out the version compatibility here:
http://travis-ci.org/#!/jnunemaker/twitter
It shows the twitter gem working with Ruby installs as low as 1.8.7.
For me, it was an issue with having the correct dependent gems, as well as the correct versions.
Here's how I got it working:
I ran:
sudo gem list
And compared the versions of specific gems with what I found here:
https://github.com/jnunemaker/twitter/blob/master/HISTORY.md (I simply searched for the word 'dependency' to see which versions twitter cared about.
I also found this diff:
https://github.com/jnunemaker/twitter/commit/ac8114c1f6ba2da20c2267d3133252c2ffc6b6a3
And I compared the gems listed there with what I had installed, and I just made sure my system lined up with what I was seeing in the version notes. Oftentimes what happened is that I had multiple versions of a gem, and for some reason, the lower version was taking precedence.
I'm not sure why I still have to add
gem 'twitter', '1.7.1'
to my Gemfile, but alas, that's the last step required in order to get this stuff working.
Don't forget to restart your server, and you should be good!

Resources