Created
November 13, 2014 21:46
-
-
Save mark/d28947ccac284649d673 to your computer and use it in GitHub Desktop.
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
Marks-MacBook-Pro:code_scraps markjosef$ irb | |
irb(main):001:0> require './private_clobbering' | |
=> true | |
irb(main):002:0> obj = MyClass.new | |
=> #<MyClass:0x007ff8220fc680> | |
irb(main):003:0> obj.public_a | |
Public A | |
Private B | |
=> nil | |
irb(main):004:0> obj.public_b | |
Public B | |
Private B | |
=> nil | |
irb(main):005:0> obj.my_public_method | |
Public C | |
Private B | |
=> nil |
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 ModuleA | |
def public_a | |
puts "Public A" | |
my_private_method | |
end | |
private | |
def my_private_method | |
puts "Private A" | |
end | |
end | |
module ModuleB | |
def public_b | |
puts "Public B" | |
my_private_method | |
end | |
private | |
def my_private_method | |
puts "Private B" | |
end | |
end | |
class MyClass | |
include ModuleA | |
include ModuleB | |
def my_public_method | |
puts "Public C" | |
my_private_method | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment