Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Error during running a ruby file using irb on Netbeans 6.9.1

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am using Netbeans 6.9.1 and imported a "what i think is a rails project" - it has a rake file that does among other things creating gems, specs and stuff from a bunch of .rb files. But you see it is no web application, so perhaps it is just a Ruby project with rake for build. Anyways, my objective is to run a Ruby file called the_ruby.rb - code snippet as follows:



I kind of thought it's cool to run it using IRB in NB (got fed up with using Eclipse Aptana Studio's debugger, which is a different issue altogether). These were what I did to invoke the method get_somedata():

1. Read the input file for the first parameter:

file = File.open("path-to-file.xml", "rb")
contents = file.read
file.close

2. Secondly, I figured I need to add up all dependencies to the $LOAD_PATH or $:

Firstly, the following observation

>>$:

>>$:
=> ["C:/Users/mcn/myproj/workspaces/ws2/projec/lib-IC:/Users/mcn/myproj/workspaces/ws2/projec/test", "C:/Users/mcn/myproj/workspaces/ws2/projec/spec", "C:/Program Files/NetBeans 6.9.1/ruby/jruby-1.5.1/lib/ruby/site_ruby/1.8", "C:/Program Files/NetBeans 6.9.1/ruby/jruby-1.5.1/lib/ruby/site_ruby/shared", "C:/Program Files/NetBeans 6.9.1/ruby/jruby-1.5.1/lib/ruby/1.8", "."]

Attempt-1: I tried a link: http://rubynotebook.blogspot.in/2013/01/load-or-require-files-into-irb.html

Dir.glob("C:/Users/mcn/myproj/workspaces/ws2/projec/lib/*.rb")
require ("./lib/the_ruby.rb")

LoadError: no such file to load -- depend1
from ./lib/the_ruby.rb:4:in `require'
from ./lib/the_ruby.rb:4
from ./lib/the_ruby.rb:6:in `require'
from (irb):6


Do I need to do something after the Dir.glob but before the require tp make this work?

Attempt-2: Then I read up more on LOAD_PATH and got to a link: http://stackoverflow.com/questions/2587128/what-is-the-quickest-way-to-recursively-add-directories-onto-the-load-path-in-r

Again, I was clueless how this is going to add files in my ./lib/*.rb files to the LOAD_PATH. As I suspected doing a $: did not show any of the .rb files.

Anyways, just being optimistic and awaiting magic, I tried to invoke a instance nmethod:



Gave the following error:

NameError: uninitialized constant MyRubyCaller
from (irb):16
>>

I am not sure what I am doing wrong, but I do suspect this has to do to the .rb files not being in LOAD_PATH. How do I run this on IRB. Please advice and help.

Regards
Mahesh
 
What's gotten into you? Could it be this tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic