Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run module from Ruby script #535

Closed
fplazaonate opened this issue Aug 22, 2024 · 1 comment
Closed

How to run module from Ruby script #535

fplazaonate opened this issue Aug 22, 2024 · 1 comment

Comments

@fplazaonate
Copy link

Describe the bug

Hi,
I would like to initialize Environment Modules from a ruby script.
I have tried to import the file "/usr/share/modules/init/ruby.rb".
After that, I can't call the module function because it is a reserved keyword in ruby.

To Reproduce

Steps to reproduce the behavior:

1 - Create a test.rb script with the following content

# Load the Environment Modules system into Ruby
require '/usr/share/modules/init/ruby.rb'

# Example usage: Load a module
module('load python')

2 - Execute the script

$ruby test.rb
test.rb:5: syntax error, unexpected '\n', expecting '.' or &. or :: or '['
module('load python')
@xdelaruelle
Copy link
Member

Hello Florian,

As you say, module is a specific keyword in Ruby. So module is defined for this language as a module method from the ENVModule class.

Some usage example:

require '/usr/share/Modules/init/ruby.rb'
ENVModule.module('list')
ENVModule.module('load', '-v', 'dot')
ENVModule.module('list')

Output of this script

$ ruby test.rb
No Modulefiles Currently Loaded.
Loading dot
Currently Loaded Modulefiles:
 1) dot

I will update the documentation to provide this example.

@xdelaruelle xdelaruelle removed the bug label Aug 22, 2024
@xdelaruelle xdelaruelle changed the title Ruby initialization script does not work How to run module from Ruby script Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants