Help with Ruby Script Outside of Codecademy


#1

I am having trouble with creating a module that makes gem usage easier. So far I only have one method that is supposed to install a gem in a different (maybe easier maybe not) way.
Here's my codes so far:

module GemHandler
    def install(gem1)
        gem install gem1
    end
end

#To test GemHandler
include GemHandler
install('gosu')

However, when I ran this using

ruby GemHandler.rb

in the command prompt, it threw me the error of

GemHandler.rb:3:in 'install': stack level too deep (SystemStackError)
    from C:/Path/to/GemHandler.rb:3:in 'install'
    from C:/Path/to/GemHandler.rb:3:in 'install'
    from C:/Path/to/GemHandler.rb:3:in 'install'
    from C:/Path/to/GemHandler.rb:3:in 'install'
    from C:/Path/to/GemHandler.rb:3:in 'install'
    from C:/Path/to/GemHandler.rb:3:in 'install'
    from C:/Path/to/GemHandler.rb:3:in 'install'
    from C:/Path/to/GemHandler.rb:3:in 'install'
     ... 10068 levels ...
    from C:/Path/to/GemHandler.rb:3:in 'install'
    from C:/Path/to/GemHandler.rb:3:in 'install'
    from C:/Path/to/GemHandler.rb:3:in 'install'
    from C:/Path/to/GemHandler.rb:9:in '<main>'

Does anyone know what 'stack level' is? How do I fix this error? My code seems like valid Ruby. Thanks in advance!


rzach123



#2

@rzach123
Try it by using

 module GemHandler
    def my_install(gem1)
        gem install gem1
    end
end

#To test GemHandler
include GemHandler
my_install('gosu')

#3

Good idea . I tried it but it didn't work. Thanks Though!

I found code that did work. instead of using

gem install gem1

I used

system("gem install #{gem1}")

Thanks Though!