shiritori 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shiritori/search_method.rb +5 -9
- data/lib/shiritori/shiritori.rb +15 -9
- data/lib/shiritori/version.rb +1 -1
- data/spec/shiritori/random_method_spec.rb +1 -4
- data/spec/spec_helper.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ca46091473a69da8cca24df97a965bfd65f6300
|
4
|
+
data.tar.gz: a50c380b8b86bfb402d2641da8d7477eda101b8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90aae5e28b8c64edb6097fb5434f79716776f8cd86038876824028e10cc732f163cc5ee04dda157ff6a91e308a8dcf396b84f14a0a946e9b3e01f43b964e4cf1
|
7
|
+
data.tar.gz: 29c19a4710ee8a3ee4ac88aab3e86dc8ae4d464aa9b158f9a0a2b1660fac61aa5b71e4ec04dd3b759bba9d633955cfb58a76a62ddeddb3533355a0511eabd4f3
|
@@ -4,20 +4,16 @@ module Shiritori
|
|
4
4
|
|
5
5
|
def get_all_method
|
6
6
|
@check_list = {}
|
7
|
-
@method_list =
|
8
|
-
|
9
|
-
scan_method
|
7
|
+
@method_list = scan_methods
|
10
8
|
|
11
9
|
@method_list - UNUSE_METHOD
|
12
10
|
end
|
13
11
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
12
|
+
def scan_methods(klass = BasicObject)
|
13
|
+
klasses = ObjectSpace.each_object(Class).to_a
|
14
|
+
klasses |= klasses.map(&:singleton_class)
|
17
15
|
|
18
|
-
|
19
|
-
scan_method(subclass) if klass != subclass && @check_list[subclass].nil?
|
20
|
-
end
|
16
|
+
klasses.map(&:instance_methods).inject(&:|)
|
21
17
|
end
|
22
18
|
end
|
23
19
|
end
|
data/lib/shiritori/shiritori.rb
CHANGED
@@ -3,7 +3,7 @@ require 'readline'
|
|
3
3
|
|
4
4
|
module Shiritori
|
5
5
|
class Main
|
6
|
-
attr_reader :current_object, :chain_count, :error_count, :mode, :
|
6
|
+
attr_reader :current_object, :chain_count, :error_count, :mode, :used_method_list
|
7
7
|
include SearchMethod
|
8
8
|
include View
|
9
9
|
|
@@ -34,7 +34,7 @@ module Shiritori
|
|
34
34
|
def update(action: nil, object: nil)
|
35
35
|
if action
|
36
36
|
@all_method.delete(action)
|
37
|
-
@
|
37
|
+
@used_method_list << action
|
38
38
|
@current_object = object
|
39
39
|
@chain_count += 1
|
40
40
|
end
|
@@ -53,7 +53,7 @@ module Shiritori
|
|
53
53
|
@all_method = get_all_method
|
54
54
|
@current_class = Object
|
55
55
|
@current_chain = []
|
56
|
-
@
|
56
|
+
@used_method_list = []
|
57
57
|
@chain_count = 0
|
58
58
|
@error_count = 0
|
59
59
|
@success = false
|
@@ -68,7 +68,7 @@ module Shiritori
|
|
68
68
|
|
69
69
|
begin
|
70
70
|
Thread.new do
|
71
|
-
timeout(TIME_LIMIT) do
|
71
|
+
Timeout.timeout(TIME_LIMIT) do
|
72
72
|
@current_object = eval(command.chomp)
|
73
73
|
end
|
74
74
|
end.join
|
@@ -116,7 +116,13 @@ module Shiritori
|
|
116
116
|
command = command.chomp.sub(/^\./, '')
|
117
117
|
|
118
118
|
begin
|
119
|
-
|
119
|
+
begin
|
120
|
+
object = Marshal.load(Marshal.dump(current_object))
|
121
|
+
rescue Exception => ex
|
122
|
+
object = current_object
|
123
|
+
end
|
124
|
+
|
125
|
+
result = try_method_chain(command, object)
|
120
126
|
|
121
127
|
redo unless result
|
122
128
|
|
@@ -132,7 +138,7 @@ module Shiritori
|
|
132
138
|
puts "Exec command #{[@current_object.to_ss, command].join('.')}"
|
133
139
|
@current_chain << command
|
134
140
|
update(action: action, object: object)
|
135
|
-
|
141
|
+
elsif used_method_list[action]
|
136
142
|
$error_message = "#{action} is already used."
|
137
143
|
raise Shiritori::UseSameMethodError
|
138
144
|
end
|
@@ -145,7 +151,7 @@ module Shiritori
|
|
145
151
|
end
|
146
152
|
end
|
147
153
|
|
148
|
-
def
|
154
|
+
def try_method_chain(command, object)
|
149
155
|
method_name = command.scan(METHOD_PATTERN).first.to_sym
|
150
156
|
result = [method_name]
|
151
157
|
|
@@ -159,7 +165,7 @@ module Shiritori
|
|
159
165
|
Thread.new do
|
160
166
|
raise NoMethodError unless object.respond_to?(method_name)
|
161
167
|
|
162
|
-
timeout(TIME_LIMIT) do
|
168
|
+
Timeout.timeout(TIME_LIMIT) do
|
163
169
|
result << eval('object.' + command)
|
164
170
|
end
|
165
171
|
end.join
|
@@ -177,7 +183,7 @@ module Shiritori
|
|
177
183
|
|
178
184
|
private
|
179
185
|
def help_me(current_object)
|
180
|
-
can_use_methods = current_object.methods -
|
186
|
+
can_use_methods = current_object.methods - used_method_list
|
181
187
|
|
182
188
|
new_line
|
183
189
|
|
data/lib/shiritori/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED