Created
May 23, 2015 18:10
-
-
Save KamilLelonek/1d344c17ee33b5155050 to your computer and use it in GitHub Desktop.
Ruby `module_function` example
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 B | |
module_function | |
def b | |
puts 'b' | |
end | |
end | |
B.b # => 'b' | |
class IncludeB | |
include B | |
end | |
IncludeB.b # => undefined method `b' for IncludeB:Class (NoMethodError) | |
IncludeB.new.b # => private method `b' called for #<IncludeB:0x007fbf9a07d828> (NoMethodError) | |
class ExtendB | |
extend B | |
end | |
ExtendB.b # => private method `b' called for ExtendB:Class (NoMethodError) | |
ExtendB.new.b # => undefined method `b' for #<ExtendB:0x007fd4b48cd530> (NoMethodError) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment