Skip to content

Instantly share code, notes, and snippets.

@nikita8
Last active November 13, 2018 05:12
Show Gist options
  • Save nikita8/b3dfddad0d31541a458b90019241fb77 to your computer and use it in GitHub Desktop.
Save nikita8/b3dfddad0d31541a458b90019241fb77 to your computer and use it in GitHub Desktop.
Private method in Ruby
#Ruby
class User
attr_accessor :user_name
def initialize(user_name, password)
@user_name = user_name
@password = password
end
def get_user_password
secret_password
end
private
def secret_password
@password
end
end
u = User.new("hello", "password")
puts "username: #{u.user_name}"
puts "password: #{u.get_user_password}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment