Skip to content

Instantly share code, notes, and snippets.

@karuppasamy
Created November 12, 2018 09:41
Show Gist options
  • Select an option

  • Save karuppasamy/a26547be3bd9efd91cbdcfbe59db1411 to your computer and use it in GitHub Desktop.

Select an option

Save karuppasamy/a26547be3bd9efd91cbdcfbe59db1411 to your computer and use it in GitHub Desktop.

Revisions

  1. karuppasamy created this gist Nov 12, 2018.
    44 changes: 44 additions & 0 deletions module_private_public.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    module Bar
    def self.included(base)
    class << base
    def public_method # public method
    puts "public method"
    end

    def call_private # public method
    puts "Call Private from Public"
    private_method
    end

    private
    def private_method
    puts "Private method"
    end
    end
    end

    def module_method
    puts "module method"
    end

    def call_module_private_method
    puts "Call module private method from module inst"
    module_private_method
    end

    private
    def module_private_method
    puts "module private method"
    end
    end

    class Foo
    include Bar
    end

    Foo.public_method
    Foo.call_private
    Foo.private_method # fail
    Foo.new.module_method
    Foo.new.call_module_private_method
    Foo.new.module_private_method # fail