Skip to content

How to run module from Ruby script #535

Closed

Description

@fplazaonate

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')

Activity

  1. xdelaruelle commented on Aug 22, 2024

    @xdelaruelle
    Collaborator

    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.

  2. changed the title [-]Ruby initialization script does not work[/-] [+]How to run `module` from Ruby script[/+] on Aug 22, 2024
  3. added a commit that references this issue on Sep 10, 2024
    672e287
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions