-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses_objects.rb
More file actions
29 lines (25 loc) · 794 Bytes
/
classes_objects.rb
File metadata and controls
29 lines (25 loc) · 794 Bytes
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
class Song
@@name = 1 # class variable, share accross all classes, all objects and subclasses
@name = "Instance variable of class" # Instance variable of class (class (self) itself is an object)
def initialize(name, singer, year)
# These are instance variables of object, unique to an object
@name = name
@singer = singer
@year = year
end
def display
puts "Published name: #{@name}"
puts "Published singer: #{@singer}"
puts "Published year: #{@year}"
end
def self.display_classinstance
puts "Self: #{@name}"
end
end
song1 = Song.new("Perfect", "Ed", 2012) # Object ID
song2 = Song.new("abc", "Ed", 2011) # Object ID
("abc", "Ed", 2011).display
song1.display
Song.display_classinstance
Song.display_classinstance
# song1.dance - noMethodError