Using ice_cube Ruby gem in IRB - ruby

I'm trying to use a Ruby gem called ice_cube in IRB, but it doesn't work:
[~]$ rvm gemset create ice
'ice' gemset created (/home/joe/.rvm/gems/ruby-1.9.2-p320#ice).
[~]$ rvm gemset use ice
Using ruby-1.9.2-p320 with gemset ice
[~]$ gem install ice_cube
Fetching: ice_cube-0.8.0.gem (100%)
Successfully installed ice_cube-0.8.0
1 gem installed
Installing ri documentation for ice_cube-0.8.0...
Installing RDoc documentation for ice_cube-0.8.0...
[~]$ irb --simple-prompt
>> require 'ice_cube'
=> true
>> schedule = Schedule.new(Time.now)
NameError: uninitialized constant Object::Schedule
from (irb):2
from /home/joe/.rvm/rubies/ruby-1.9.2-p320/bin/irb:16:in `<main>'
What am I doing wrong? (I'm a beginner Ruby programmer.)

It should be:
schedule = IceCube::Schedule.new(Time.now)

include IceCube
schedule = Schedule.new(Time.now)
Or you can first include the module into global namespace, then you can use whatever it is in that module.

Had similar issue, Try Restarting your Rails Application.

Related

Ruby Gem adaptor MySQL error

I am getting the below error while using the MySQL gem; Tried mysql2 and it also gives the same error.
-bash-4.1$ gem list
*** LOCAL GEMS ***
mysql (2.9.1)
-bash-4.1$ ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
-bash-4.1$ irb
irb(main):001:0> require 'mysql'
NameError: uninitialized constant Mysql
from ./mysql.rb:10
from (irb):1:in `require'
from (irb):1
from :0
irb(main):002:0>
Please let me know if there is a solution for this; thanks!
Are you using bundler/rvm? If so, start irb with:
bundle exec irb
make sure you are in the right gemset and ruby version from where you are accessing the gem.
Before typing in the irb, check what gemset you are in:
rvm gemset list
then check the gems installed in that particular gemset
rvm <my-gemset-name> do gem list
If they do not match, that is your problem and you can fix it by changing to the right gemset:
rvm use <my-gemset>
Similarly, check for ruby version, i.e if the ruby version for your installed gem and from where you are running your irb match

ruby and gems are installed but sass gem not working

I know I have ruby and gem installed because I've installed a bunch of gems previously. Additionally when I do the following
~$ ruby --version
ruby 1.8.7 (2010-08-16 patchlevel 302 [i486-linux]
~$ gem --version
1.3.7
They, as you can see, return the version--yet when I try to do this--
~$ sass --watch happy.scss:happy.css
bash: sass: command not found
I'm a relative noob to everything, but far more to ruby and gems. For the sake of revealing more or less my level of understanding things generally I've learned enough of Debian to get a an environment where I could get Clojure running and get a web app working (taken me almost a year of spare time to do that--I knew virtually nothing of programming previoiusly). I'm trying to get sass working to ease my mental load in the webpage design side of things and I'm just hitting a brick wall on this.
Would this be a PATH issue? If so what needs to be on the path so that one gem works --
BTW here's what happens when I install sass--
# gem install sass
Successfully installed sass-3.2.5
1 gem installed
Installing ri documentation for sass-3.2.5...
Installing RDoc documentation for sass-3.2.5...
Any help anyone can give will be much appreciated. I've been at this one all day and can't figure it out for the life of me.
justin ⮀ ~ ⮀ gem install sass
Fetching: sass-3.2.5.gem (100%)
Successfully installed sass-3.2.5
1 gem installed
justin ⮀ ~ ⮀ sass -v
Sass 3.2.5 (Media Mark)
seems ok to me. I would check your path.
The proper PATH would depend on where your gems get installed. I use RVM so it will be different. You could try to throw an exception in your ruby code with rubygems loaded this should give you a starting point.
> rails c
Loading development environment (Rails 3.2.11)
1.9.3p362 :001 > throw test
ArgumentError: wrong number of arguments (0 for 2..3)
from (irb):1:in `test'
from (irb):1
from /Users/justin/.rvm/gems/ruby-1.9.3-p362#rails3.2/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /Users/justin/.rvm/gems/ruby-1.9.3-p362#rails3.2/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /Users/justin/.rvm/gems/ruby-1.9.3-p362#rails3.2/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:5:in `require'
from script/rails:5:in `<main>'
so from that i see /Users/justin/.rvm/gems/ruby-1.9.3-p362#rails3.2/gems/railties-3.2.11/lib/rails/commands/console.rb
so my bin path is at /Users/justin/.rvm/gems/ruby-1.9.3-p362#rails3.2/bin
and if i
> ls /Users/justin/.rvm/gems/ruby-1.9.3-p362#rails3.2/bin
b2json capify fog html2haml nokogiri rails ri sass-convert therubyracer tilt
bundle coderay geocode httpclient oauth rake2thor ruby_noexec_wrapper scss thin tt
cap erubis haml j2bson rackup rdoc sass sprockets thor
boom sass
so in my case I would want to add /Users/justin/.rvm/gems/ruby-1.9.3-p362#rails3.2/bin
but i use RVM so it does that for me.

rails not working

I installed rails a while back.
Now when I do rails new foo at the terminal nothing happens.
I have ruby 1.9.2. When I do gem list, I can see rails (3.2.8). However executing any rails commands, including rails itself does nothing.
I also tried sudo gem cleanup and sudo gem clean. sudo gem uninstall rails and then sudo gem install rails. This gives me
Fetching: rails-3.2.8.gem (100%)
Successfully installed rails-3.2.8
1 gem installed
Installing ri documentation for rails-3.2.8...
file 'lib' not found
Installing RDoc documentation for rails-3.2.8...
file 'lib' not found
Any help would be appreciated.
Edit: The problem was that I had defined a shell alias called rails which was masking rails.
Do gem install rails - no sudo
Then rails new foo

How do I use RVM to create a gemset of three gems?

I want to play around with three similar Ruby gems called 'yahoofinance' 'yahoo-finance' and 'yahoo_stock'. I'm interested in how each gem works with Yahoo Finance. So I start with creating an rvm gemset,
[sandbox]$ rvm gemset create finance
'finance' gemset created (/Users/milktrader/.rvm/gems/ruby-1.9.2-p0#finance).
Then I use it,
[sandbox]$ rvm gemset use finance
Now using gemset 'finance'
Then I attached it to a ruby,
[sandbox]$ rvm 1.9.2-head#finance
Then I installed the three gems above,
[sandbox]$ gem install yahoo-finance yahoofinance yahoo_stock
Successfully installed yahoo-finance-0.0.2
Successfully installed yahoofinance-1.2.2
Successfully installed yahoo_stock-1.0.2
3 gems installed
.
.
.
Installing RDoc documentation for yahoo_stock-1.0.2...
Now I'm incorrectly assuming I can require all three gems in an irb sesssion. Only one of them returns true.
ruby-1.9.2-head > require 'yahoofinance'
=> true
While the other two throw errors.
ruby-1.9.2-head > require 'yahoo-finance'
LoadError: no such file to load -- yahoo-finance
ruby-1.9.2-head > require 'yahoo_stock'
SyntaxError: ...
Is there a problem with the gems or my installation?
NOTE: I am foggy about the rvm gemset use command, and it's probably not being used correctly above.
[sandbox]$ gem list
*** LOCAL GEMS ***
bundler (1.0.7)
rake (0.8.7)
yahoo-finance (0.0.2)
yahoo_stock (1.0.2)
yahoofinance (1.2.2)
I initially hit the same errors you did, so it's not environment.
The issue with yahoo-finance is that it must be required as yahoo_finance.
The issue with yahoo_stock is a syntax error, indicating that the file is being loaded, but not interpreted correctly. Upon inspecting the Github project's changelog, we see that this syntax error in history.rb for Ruby 1.9.1 was fixed in version 1.0.5, but the version in the central gem repository is 1.0.2. Turns out that the gem's owner now calls the gem nas-yahoo_stock, so running gem install nas-yahoo_stock should resolve that issue.

rvm, irb and require - not working for installed gems under irb

I have just installed rvm today and it looks really handy/powerful.
I think I am getting the hang of it, but...
When using an rvm installed ruby, and running irb, when I require an installed gem, something, like 'rvm', I get:
> kimptoc$ rvm use 1.8.7
Using /Users/kimptoc/.rvm/gems/ruby-1.8.7-p302
> kimptoc$ gem list
*** LOCAL GEMS ***
abstract (1.0.0)
...
rvm (1.0.11)
...
> kimptoc$ irb
ruby-1.8.7-p302 > require 'rvm'
LoadError: no such file to load -- rvm
from (irb):1:in `require'
from (irb):1
But when using the "system" ruby, it works fine.
Historically I have been using sudo gem install ... and so the "system" gems are generally installed that way. Could that be my problem? Do I need to uninstall these to fix things?
I am running OSX 10.6.4. "system" is the default OSX ruby, 1.8.7 (p174)
Try require 'rubygems' first.
> rvm use 1.8.7
> rvm info
(Find the homes -> gem directory)
> ls -al ~/.rvm/gems/ruby-1.8.7 (Substitute your gem directory as needed)
Is your gem in this directory?
Generally speaking, using sudo gem install with rvm is a bad idea.
As of Ruby 1.9.3 you no longer need, can, require rubygems and you only need to require rvm.
If you want to use it in your .irbrc file for using wirble or awsome print you can use a simple trick to avoid a login error saying it can't include or 'rubygems' or 'rvm'
if RUBY_VERSION > "1.8.7"
require 'rvm'
else
require 'rubygems'
end
require 'wirble'
Wirble.init
Wirble.colorize
Including both rubygems and rvm does not seem logical because RVM replaces rubygems in some sort to handle the gems and gem repositories.
Note: For Ruby 1.8 you must require 'rubygems' before requiring any gems.
source : https://guides.rubygems.org/rubygems-basics/

Resources