Skip to content

Instantly share code, notes, and snippets.

@scottchiang
Created October 11, 2012 04:34
Show Gist options
  • Save scottchiang/3870179 to your computer and use it in GitHub Desktop.
Save scottchiang/3870179 to your computer and use it in GitHub Desktop.
Object privacy
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