Created
October 11, 2012 04:34
-
-
Save scottchiang/3870179 to your computer and use it in GitHub Desktop.
Object privacy
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
class BankAccount | |
def initialize(customer_name, type, acct_number) | |
@customer_name = customer_name | |
@type = type | |
@acct_number = acct_number | |
end | |
def name | |
@customer_name | |
end | |
def acct_type | |
@type | |
end | |
def acct_number | |
@partial_num = @acct_number.split('-').join | |
@partial_num = @partial_num.gsub(/\d{5}/, "*****") | |
end | |
def acct_type=(type) | |
@type = type | |
end | |
def to_s | |
"#{@customer_name}: #{@type}# #{self.acct_number}" | |
end | |
end | |
my_acct = BankAccount.new("Scott Chiang", "Checking", "333-333-333") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment