-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.rb
More file actions
77 lines (58 loc) · 1.24 KB
/
class.rb
File metadata and controls
77 lines (58 loc) · 1.24 KB
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
65
66
67
68
69
70
71
72
73
74
class Pet
def pet_noise(noise)
@noise = noise
end
def speak
puts "Your pet says #{@noise}, #{@noise}!!"
end
def pet_age(years)
puts "Your pet is #{years} years old. What a youngin'!"
end
def pet_color(color)
puts "Your pet is a lovely shade of #{color}."
end
end
class Owner
def owner_name(name)
puts "The pet's owners name is #{name}."
end
def owner_age(age)
puts "The owners age is #{age}."
end
end
#extensions
# 5 * 5
5.send(:*, 5)
# "omg".upcase
"omg".send(:upcase)
# ['a', 'b', 'c'].at(1)
['a', 'b', 'c'].send(:at, 1)
# ['a', 'b', 'c'].insert(2, 'o', 'h', 'n', 'o')
['a', 'b', 'c'].send(:insert, 2, 'o', 'h', 'n', 'o')
#{}.size
{}.send(:size)
# 6.send(:-, 32)
6 - 32
# {html: true, json: false}.send(:keys)
{html: true, json: false}.keys
# "MakerSquare".send(:*, 6)
"MakerSquare" * 6
# "MakerSquare".send(:split, 'a')
"MakerSquare".split('a')
# ['alpha', 'beta'].send(:[], 3)
['alpha', 'beta'].[](3)
# dog = Pet.new
# dog.speak
# dog.pet_age(5)
# dog.pet_color("yellow")
# bob = Owner.new
# bob.owner_name("Bob")
# bob.owner_age(22)
# class Marker
# def set_color(my_color)
# @color = my_color
# end
# def write
# Kernel.puts("I am writing with a #{@color} marker!")
# end
# end