-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.rb
48 lines (40 loc) · 1.01 KB
/
classes.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
#!/usr/bin/ruby
$global_variable = 10
class Customer
@@no_of_customers = 0
def initialize(id, name, addr)
@cust_id = id
@cust_name = name
@cust_addr = addr
end
def display
puts "Instance Variable"
puts"customer id is #@cust_id"
puts"customer name is #@cust_name"
puts"customer addr is #@cust_addr"
end
def total_no_of_customers()
@@no_of_customers += 1
puts "Total number of customers: #@@no_of_customers"
end
end
class Helloworld
def print_method
puts 'Hello Ruby!'
end
end
class Global
def print_global
puts "The value of global variable is #$global_variable "
end
end
cust1 = Customer.new("1", "John", "Wisdom Apartments, Ludhiya")
cust2 = Customer.new("2", "Poul", "New Empire road, Khandala")
cust1.display
cust1.total_no_of_customers
cust2.display
cust2.total_no_of_customers
object = Helloworld.new
object.print_method
object2 = Global.new
object2.print_global