Created
August 9, 2011 18:20
-
-
Save mcornell/1134791 to your computer and use it in GitHub Desktop.
Override Module private Method in Ruby/JRuby
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
class ClassIncludingModule | |
include OverrideMe | |
do_something | |
end |
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
class ClassIncludingModuleWithOverride | |
include OverrideMe | |
do_something | |
def please_override | |
puts "I likey what you do" | |
end | |
end |
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
class ClassIncludingOverrideModule | |
include OverrideMe | |
include FixMe | |
do_something | |
end |
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 FixMe | |
def self.included(cls) | |
cls.extend ClassMethods | |
end | |
# A collection of class methods that generate helper methods that are mixed into a calling class. | |
module ClassMethods | |
private | |
def please_override | |
puts "I likey what you do" | |
end | |
end | |
end |
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 OverrideMe | |
def self.included(cls) | |
cls.extend ClassMethods | |
end | |
# A collection of class methods that generate helper methods that are mixed into a calling class. | |
module ClassMethods | |
def do_something | |
please_override | |
end | |
private | |
def please_override | |
puts "I no likey what you do" | |
end | |
end | |
end |
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
irb(main):001:0> module OverrideMe | |
irb(main):002:1> def self.included(cls) | |
irb(main):003:2> cls.extend ClassMethods | |
irb(main):004:2> end | |
irb(main):005:1> | |
< of class methods that generate helper methods that are mixed into a calling class. | |
irb(main):007:1* module ClassMethods | |
irb(main):008:2> | |
irb(main):009:2* def do_something | |
irb(main):010:3> please_override | |
irb(main):011:3> end | |
irb(main):012:2> | |
irb(main):013:2* private | |
irb(main):014:2> | |
irb(main):015:2* def please_override | |
irb(main):016:3> puts "I no likey what you do" | |
irb(main):017:3> end | |
irb(main):018:2> end | |
irb(main):019:1> end | |
=> nil | |
irb(main):020:0> class ClassIncludingModule | |
irb(main):021:1> include OverrideMe | |
irb(main):022:1> | |
irb(main):023:1* do_something | |
irb(main):024:1> end | |
I no likey what you do | |
=> nil | |
irb(main):025:0> class ClassIncludingModuleWithOverride | |
irb(main):026:1> include OverrideMe | |
irb(main):027:1> | |
irb(main):028:1* do_something | |
irb(main):029:1> | |
irb(main):030:1* def please_override | |
irb(main):031:2> puts "I likey what you do" | |
irb(main):032:2> end | |
irb(main):033:1> end | |
I no likey what you do | |
=> nil | |
irb(main):034:0> | |
.... | |
irb(main):101:0> module FixMe | |
irb(main):102:1> def self.included(cls) | |
irb(main):103:2> cls.extend ClassMethods | |
irb(main):104:2> end | |
irb(main):105:1> | |
< of class methods that generate helper methods that are mixed into a calling class. | |
irb(main):107:1* module ClassMethods | |
irb(main):108:2> | |
irb(main):109:2* private | |
irb(main):110:2> | |
irb(main):111:2* def please_override | |
irb(main):112:3> puts "I likey what you do" | |
irb(main):113:3> end | |
irb(main):114:2> end | |
irb(main):115:1> end | |
=> nil | |
irb(main):116:0> class ClassIncludingOverrideModule | |
irb(main):117:1> include OverrideMe | |
irb(main):118:1> include FixMe | |
irb(main):119:1> | |
irb(main):120:1* do_something | |
irb(main):121:1> | |
irb(main):122:1* end | |
I likey what you do | |
=> nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment