Created
March 1, 2015 09:41
-
-
Save gee-forr/de3051ec64883fd9ee14 to your computer and use it in GitHub Desktop.
Dynamically load a module from string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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