Created
September 4, 2008 00:39
-
-
Save atduskgreg/8696 to your computer and use it in GitHub Desktop.
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
module One | |
def one | |
"one" | |
end | |
end | |
module Two | |
def two | |
"two" | |
end | |
end | |
class Moduler | |
def initialize array_of_mods | |
array_of_mods.each{|m| Moduler.send(:include, Moduler.constantize(m)) } | |
end | |
def self.constantize(camel_cased_word) | |
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word | |
raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!" | |
end | |
Object.module_eval("::#{$1}", __FILE__, __LINE__) | |
end | |
end | |
m = Moduler.new( ["One", "Two"] ) | |
puts m.one | |
puts m.two |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment