Skip to content

Instantly share code, notes, and snippets.

@EmanuelCadems
Created April 29, 2016 18:06
Show Gist options
  • Save EmanuelCadems/45fc37106651e83148514b7aa5aa7519 to your computer and use it in GitHub Desktop.
Save EmanuelCadems/45fc37106651e83148514b7aa5aa7519 to your computer and use it in GitHub Desktop.
How to define private method for using into a class method
class Ej
class << self
def bar
my_method
end
private
def my_method
'hola mundo'
end
end
end
p Ej.bar
p Ej.my_method
@EmanuelCadems
Copy link
Author

EmanuelCadems commented Apr 29, 2016

The same thing:

class Ej
  class << self

    private
      def my_method
        'hola mundo'
      end
  end

  def self.bar
    my_method
  end

end


p Ej.bar
p Ej.my_method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment