Created
November 17, 2009 05:29
-
-
Save santosh79/236671 to your computer and use it in GitHub Desktop.
automating includes with class_eval
This file contains 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 Hello | |
def say_hello | |
puts "hello" | |
end | |
end | |
[String, Array, Hash].each do |cls| | |
cls.class_eval { include Hello } | |
end | |
"cat".say_hello | |
[1,2].say_hello | |
{:1 => true, :2 => false}.say_hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment