-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobj_27.rb
executable file
·51 lines (44 loc) · 1004 Bytes
/
robj_27.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
#!/usr/bin/env ruby
require "./ruler"
#-----------------------------------------------------------------------------
R("CodeSchool RubyBits2, level 4, challenge 6")
class Library
SYSTEMS = ['arcade', 'atari', 'pc']
attr_accessor :games
def respond_to?(name)
puts ">> #{name}"
if SYSTEMS.include?(name)
true
else
super
end
end
def method_missing(name, *args)
puts "-- Library --"
puts "-- here, name='#{name}'"
unless SYSTEMS.include?(name.to_s)
super
end
self.class.class_eval do
define_method name do
puts "# this method is #{name}"
find_by_system(name)
end
end
send(name)
end
private
def find_by_system(system)
games.select { |game| game.system == system }
end
end
class Game
attr_accessor :system
end
l0 = Library.new
l0.games = [Game.new, Game.new, Game.new]
#puts "----"
#puts l0.respond_to?("atari")
#puts l0.respond_to?("atari2")
puts "--- checking atari ---"
l0.atari