/
main.rb
52 lines (41 loc) · 828 Bytes
/
main.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
require_relative 'renderer'
require_relative 'text_object'
require_relative 'british_text_object'
# Extend the BritishTexObject to include the methods
# that the Renderer class requires
class BritishTextObject
def color
return colour
end
def text
return string
end
def size_inches
return size_mm / 25.4
end
end
# -------------------------------------------------------------------
# A different approach would be to modify class instances at run-time
bto = BritishTextObject.new('hello', 50.8, :blue)
# Modifiy the 'bto' instance of the BritishTextObject class
class << bto
def color
colour
end
def text
string
end
def size_inches
size_mm / 25.4
end
end
# Alternative syntax
def bto.color
colour
end
def bto.text
string
end
def bto.size_inches
size_mm / 25.4
end