Skip to content

Instantly share code, notes, and snippets.

@atduskgreg
Created September 4, 2008 00:39
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 atduskgreg/8696 to your computer and use it in GitHub Desktop.
Save atduskgreg/8696 to your computer and use it in GitHub Desktop.
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