在下面的类中,构造函数崩溃:
class Locations
def initialize
@index = [{}]
file = File.new(NSBundle.mainBundle.pathForResource('suburbs', ofType: 'txt'), 'r')
while (line = file.gets)
location = Location.parse(line)
for x in 0...@index.length do
end
end
file.close
self
end
end
如果我删除for循环,它不会崩溃:
class Locations
def initialize
@index = [{}]
file = File.new(NSBundle.mainBundle.pathForResource('suburbs', ofType: 'txt'), 'r')
while (line = file.gets)
location = Location.parse(line)
end
file.close
self
end
end
如果我交换for循环的顺序和location
赋值,它也不会崩溃:
class Locations
def initialize
@index = [{}]
file = File.new(NSBundle.mainBundle.pathForResource('suburbs', ofType: 'txt'), 'r')
while (line = file.gets)
for x in 0...@index.length do
end
location = Location.parse(line)
end
file.close
self
end
end
有什么想法吗?
编辑:以下是控制台输出:
*** simulator session ended with error: Error Domain=DTiPhoneSimulatorErrorDomain Code=1 "The simulated application quit." UserInfo=0x10012c9d0 {NSLocalizedDescription=The simulated application quit., DTiPhoneSimulatorUnderlyingErrorCodeKey=-1}
rake aborted!
Command failed with status (1): [DYLD_FRAMEWORK_PATH="/Applications/Xcode.a...]
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `call'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `sh'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils_ext.rb:37:in `sh'
/Library/RubyMotion/lib/motion/project/template/ios.rb:112:in `block in <top (required)>'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/usr/local/Cellar/ruby/1.9.3-p385/lib/ruby/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in `<top (required)>'
/usr/local/Cellar/ruby/1.9.3-p385/bin/rake:23:in `load'
/usr/local/Cellar/ruby/1.9.3-p385/bin/rake:23:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Tasks: TOP => simulator
Process finished with exit code 1