-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrategy_pattern.rb
More file actions
57 lines (47 loc) · 909 Bytes
/
Copy pathstrategy_pattern.rb
File metadata and controls
57 lines (47 loc) · 909 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
48
49
50
51
52
53
54
55
56
57
class Printer
def initialize(printable)
@printable = printable
end
def print_preview
puts '-> starting the printing preview...'
@printable.print_preview
puts '-> happy with the preview? shall I print now?'
end
def print
puts '-> initializing...'
puts '-> ...printing'
@printable.print
puts '-> print successful'
end
end
module PreviewLess
def print_preview
puts 'no preview available'
end
end
module Printable
def print
puts "#{self.class.name} print"
end
end
class Pdf
include Printable
def print_preview
puts 'pdf preview'
end
end
class Html
include PreviewLess
include Printable
end
class Photocopy
include PreviewLess
def print
puts 'photocopy generated'
end
end
[Pdf, Html, Photocopy].each do |printable|
Printer.new(printable.new).print_preview
Printer.new(printable.new).print
puts '-------------'
end