简体   繁体   中英

irb doesn't recognize method

This is weird, and probably due to me being new to ruby. I have created a gem, it works, all the unit tests work, but when i do the following in irb it can't find the "ingredients" method;

1.9.2-p290 :002 > require "tablecloth"
 => true 
1.9.2-p290 :003 > tc = TableCloth.new "1 cup of sugar"
 => #<TableCloth:0x864a728> 
1.9.2-p290 :004 > tc.ingredients
NoMethodError: undefined method `ingredients' for #<TableCloth:0x864a728>
from (irb):4
from /home/mikey/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
1.9.2-p290 :005 > 

Entire gem is here;

https://github.com/mikeyhogarth/tablecloth

Obviously this is due to me being new to ruby. It's not actually hindering the development, I just want to know why irb can't seem to register that method in this case!

I think you are loading a different, older version of the gem in IRB than you are in your unit tests. Your unit tests probably test the gem code sitting in your development directory, but when you do require "tablecloth" in IRB it would load the gem that has been installed to your system's gem's directory. If you are using RVM, you can look at the $GEM_HOME environment variable to see what directory that is.

You probably need to run a rake task like rake install or something like that to install your gem before you can use it in irb.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM