-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source.rb
53 lines (43 loc) · 1.2 KB
/
data_source.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
53
#---
# Excerpted from "Metaprogramming Ruby 2",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http://www.pragmaticprogrammer.com/titles/ppmetr2 for more book information.
#---
# In this example, we just fake the real service.
class DS
def initialize # connect to data source...
end
def get_cpu_info(workstation_id) # ...
"2.9 Ghz quad-core"
end
def get_cpu_price(workstation_id) # ...
120
end
def get_mouse_info(workstation_id) # ...
"Wireless Touch"
end
def get_mouse_price(workstation_id) # ...
60
end
def get_keyboard_info(workstation_id) # ...
"Standard US"
end
def get_keyboard_price(workstation_id) # ...
20
end
def get_display_info(workstation_id) # ...
"LED 1980x1024"
end
def get_display_price(workstation_id) # ...
# ...and so on
150
end
end
ds = DS.new
ds.get_cpu_info(42) # => "2.9 Ghz quad-core"
ds.get_cpu_price(42) # => 120
ds.get_mouse_info(42) # => "Wireless Touch"
ds.get_mouse_price(42) # => 60