-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.rb
37 lines (31 loc) · 819 Bytes
/
class.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
class Pet
def set_woof(woof)
@woof = woof
end
def speak
puts "#{@woof} #{@woof}"
end
end
class Person
def set_identity(name, job)
@name = name
@job = job
end
def identity
puts "Hi my name is #{@name} and I work as a #{@job}"
end
end
# Convert the following methods to use the send method
5.send(:*, 5) # 5 * 5
"omg".send(:upcase) # "omg".upcase
['a', 'b', 'c'].send(:at, 1) # ['a', 'b', 'c'].at(1)
['a', 'b', 'c'].send(:insert, 2, 'o', 'h', 'n', 'o') # ['a', 'b', 'c'].insert(2, 'o', 'h', 'n', 'o')
{}.send(:size) # {}.size
{character: "Mario"}.send(:has_key?, :character) # {character: "Mario"}.has_key?(:character)
# Convert the following methods to not use the send method
6 - 32
{html: true, json: false}.keys
"MakerSquare" * 6
"MakerSquare".split('a')
array = ['alpha', 'beta']
array[3]