-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathself.rb
64 lines (46 loc) · 884 Bytes
/
self.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
56
57
58
59
60
61
62
63
64
#self act as object
# def coffee
# puts self
# end
# coffee
#below self is object of cat class
# class Cat
# def meow
# puts self
# end
# end
# Cat.new.meow
# <Cat:0x7a14c5>
#below self is used to differentiate method and local variable with same name
# class Example
# def do_something
# banana = "variable"
# puts banana
# puts self.banana
# end
# def banana
# "method"
# end
# end
# Example.new.do_something
# "variable" => puts banana
# "method" => puts self.banana
# Using Self To Define Class-Level Methods
# class Salad
# def self.buy_olive_oil
# puts "class level method"
# end
# end
# Salad.buy_olive_oil
# def ==(other)
# puts self == other #didn't understand
# end
if fork
write.close
puts "Message received: #{read.gets}"
read.close
else
read.close
write << "Buy some bananas!"
write.close
end