2

I have the problem that I want to require a ruby file.

File overview:

ExcelConversion.rb
main.rb
/classes/excelReader.rb
/classes/elementIdentifier.rb

the main.rb has the header:

require classes/excelReader
require classes/elementIdentifier

the excelReader.rb has the header:

require 'rubyXL

the elementIdentifier.rb has the header:

require 'inifile

The problem is that if I execute the main.rb file, everything works fine. But, as soon as I write require main within the ExcelConversion file I get the error:

Error Loading File ExcelConversion.rb
Error: #<LoadError: cannot load such file -- rubyXL>
C:/Program Files (x86)/SketchUp/SketchUp 2018/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:54:in 'require'
C:/Program Files (x86)/SketchUp/SketchUp 2018/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:54:in 'require'
C:/shortenedPath/ExcelConversion/classes/ExcelReader.rb:1:in '<top (required)>'
C:/shortenedPath/ExcelConversion/main.rb:1:in 'require_relative'
C:/shortenedPath/ExcelConversion/main.rb:1:in '<top (required)>'
C:/shortenedPath/ExcelConversion.rb:4:in 'require_relative'
C:/shortenedPath/ExcelConversion.rb:4:in '<top (required)>'

I don't understand how that is even possible to throw an error, since the main.rb runs without problems.


Edit: Solution
I managed to find the solution. SketchUp needs to install the gems separately. This can be achieved through the Ruby Console and the command: Gem.install "nameOfTheGem"
Then SketchUp stores a copy of the gem within it's own path and one can require it as usual.
  • 2
    Did you try requiring rubyxl at the beginning of your `ExcelConversion.rb` and seeing if that would help? Also, I see you have a require_relative in there which requires the file relative to the current path of the file, and can cause errors when run in a new context. – sakurashinken Jan 22 '18 at 20:46
  • 1
    yes I did and sadfully that didn't help.:/ the structure is still right. Checked it like 4 times. `ExcelConversion.rb` and `main.rb` are in the same folder – Timo Bergerbusch Jan 22 '18 at 20:50
  • 2
    Did you install through rubygems? There is some talk about files not being found without a require 'rubygems' statement. – sakurashinken Jan 22 '18 at 20:54
  • 1
    Yes using it in the gemfile. Already tried to reinstall them thorugh console started as admin. I'm using Win10 by the way... – Timo Bergerbusch Jan 22 '18 at 21:00
  • 1
    I tried to require them with an absolute path. That worked for `inifile.rb`, but not for `rubyXL.rb`. Maybe because the one is a single file and the other contains multiple others? – Timo Bergerbusch Jan 22 '18 at 21:16
  • 3
    @TheOneWhoMade, upvoting one of your questions or answers for an edit? That's a new one on me, and I can't say I'm impressed. – Cary Swoveland Jan 22 '18 at 21:24
  • @CarySwoveland, good point to be made. But the spelling does make the question easier to be read. Less frustrating. You'd be surprised how many people downvote because of bad spelling and caps. –  Jan 22 '18 at 21:32

0 Answers0