Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Created May 23, 2015 18:10
Show Gist options
  • Save KamilLelonek/1d344c17ee33b5155050 to your computer and use it in GitHub Desktop.
Save KamilLelonek/1d344c17ee33b5155050 to your computer and use it in GitHub Desktop.
Ruby `module_function` example
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