-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.rb
55 lines (43 loc) · 884 Bytes
/
demo.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require_relative "log"
class User
@@count = 0
include Log
def initialize(name, password, phone, address)
@name = name
@password = password
@phone = phone
@address = address
update_count
end
def show
puts "- User details"
puts "Name: #{@name}"
puts "Phone: #{@phone}"
puts "Address: #{@address}"
end
def self.count
@@count
end
private
def update_count
@@count += 1
end
end
u1 = User.new("brg", "pass123", "1234567891", "Pune, India")
u1.show
puts u1.log("User 1 logging")
puts "Total User: #{User.count}"
u2 = User.new("foo", "pass123", "4567891", "KTM, Nepal")
u2.show
puts u1.log("User 2 logging")
puts "Total User: #{User.count}"
# Exception Handling
puts ""
puts "---" * 10
begin
if 120 / 0
puts "Diving some number with zero"
end
rescue Exception => e
puts "Catching Error: #{e.message}"
end