Skip to content

Instantly share code, notes, and snippets.

@gee-forr
Created March 1, 2015 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gee-forr/de3051ec64883fd9ee14 to your computer and use it in GitHub Desktop.
Save gee-forr/de3051ec64883fd9ee14 to your computer and use it in GitHub Desktop.
Dynamically load a module from string
#!/usr/bin/env ruby
lib_name = 'matrix' # This could be your param
require lib_name # require can accept a string
klass = Kernel.const_get(lib_name.capitalize) # Kernel.const_get turns a string into a constant
klass.zero(1) # And here we're using the newly constantized string to run methods on the Matrix class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment