Last active
November 13, 2018 05:12
-
-
Save nikita8/b3dfddad0d31541a458b90019241fb77 to your computer and use it in GitHub Desktop.
Private method in Ruby
This file contains 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
#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