Skip to content

Instantly share code, notes, and snippets.

@jacegu
Created January 18, 2011 18:13
Show Gist options
  • Save jacegu/784873 to your computer and use it in GitHub Desktop.
Save jacegu/784873 to your computer and use it in GitHub Desktop.
A little example about modules and namespaces
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