Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Customer
- # attr_accessor :name
- def name ; @name ; end
- def name=(newname) ; @name = newname ; end
- # accessor for the singleton
- def self.null_customer
- @@instance ||= Customer.new
- # put the singleton in its own class!
- class << @@instance
- def name ; "ANONYMOUS" ; end
- def name=(new) ; raise "Can't change name of null customer " ; end
- def logged_in? ; false ; end
- end
- @@instance
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment