Created
January 18, 2011 18:13
-
-
Save jacegu/784873 to your computer and use it in GitHub Desktop.
A little example about modules and namespaces
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 AModule | |
class String | |
def i_like_open_classes | |
puts "#{self} hasn't been monkey patched" | |
end | |
end | |
end | |
string = String.new | |
begin | |
string.i_like_open_classes | |
rescue NoMethodError | |
puts "String hasn't been opened hence nor mokey patched" | |
end | |
my_string = AModule::String.new | |
my_string.i_like_open_classes | |
puts string.class | |
puts my_string.class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment