-
Notifications
You must be signed in to change notification settings - Fork 1
/
words.rb
94 lines (86 loc) · 1.46 KB
/
words.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class String
def trim
tr("\n", '')
.tr(' ', '')
.tr("'", '')
.tr('-', '')
.tr('sb.', '')
.tr('sw.', '')
.tr('sth.', '')
.tr('.', '')
.downcase
end
end
## Base class
class Words
attr_reader :map
## add words
def words(map)
@map = map
end
## Executed
def review
@map.each_key do |k|
full_str = k.to_s.split '_'
################ 我跟你讲我就这个表情
first_mark = true
full_str.each do |part|
print part
if first_mark
first_mark = false
else
print ' '
end
end
gets
print @map[k], "\n\n"
end
end
def listen_write
mistaken_words = Array.new
len = @map.size
print "Here's ", len, ' words today.', "\n"
progress = 0
@map.each_key do |k|
progress += 1
full_str = k.to_s
trimmed_star = full_str.trim
print @map[k], "\n"
input = gets.to_s.trim
if input.eql? trimmed_star
print 'Correct!', "\n"
else
print 'Wrong!', "\n"
print 'The correct one is: ', full_str, "\n"
mistaken_words << full_str
end
print '[', progress, '/', len, ']', "\n"
end
print 'Mistaken words:', "\n"
mistaken_words.each do |w|
print w, "\n"
end
print 'Have a nice day. :)'
end
def refer(key)
w = @map[key]
if w.nil?
return 'Unknown word:', key, "\n"
else
w
end
end
end
def review(w)
w.review
end
def listen_write(w)
w.listen_write
input = gets
end
## it defines a getter
def def_getter(ret)
define_method :get_today do
ret
end
end