forked from gcallah/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonkey_patch.rb
More file actions
47 lines (43 loc) · 906 Bytes
/
Copy pathmonkey_patch.rb
File metadata and controls
47 lines (43 loc) · 906 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module MonkeyPatch
# Public: In-Built Integer class override
# Extended Integer class methods to get the feel of how much a pseudo code
# can be related to interpreted code
# Methods are invoked on an integer
#
# Examples
#
# 10.parent
# => 5
# 10.left
# => 20
# 10.right
# => 21
refine Integer do
def parent
( self / 2 ).floor
end
def left
( 2 * self ) + 1
end
def right
( 2 * self ) + 2
end
def half
( self / 2 ).floor
end
end
# Public: In-Built Array class override
# Extended array class to add a method heap_size to be as close to the
# textbook as possible
#
# Examples
#
# [1, 2, 3, 4].heap_size
# => nil
# [1, 2, 3, 4].heap_size = 10
# [1, 2, 3, 4].heap_size
# => 10
refine Array do
attr_accessor :heap_size
end
end