class Pope
def pray!
puts 'In nomine Patris, et Filii, et Spiritus Sancti...'
end
end
pope = Pope.new
pope.pray! # => 'In nomine Patris, et Filii, et Spiritus Sancti...'
new_pope = Pope.new
new_pope.pray! # => 'In nomine Patris, et Filii, et Spiritus Sancti...'
pope == new_pope # => false
class Pope
@@instance = new
def self.instance
@@instance
end
def pray!
puts 'In nomine Patris, et Filii, et Spiritus Sancti...'
end
private_class_method :new
end
pope = Pope.new # => NoMethodError: private method 'new' called for Pope:Class
Pope.instance.pray! # => "In nomine Patris..."
pope = Pope.instance
new_pope = Pope.instance
pope == new_pope # => true
class Pope
include Singleton
def pray!
puts 'In nomine Patris, et Filii, et Spiritus Sancti...'
end
end