在浏览http://testfirst.org/learn_javascript时,我尝试在00_hello /文件夹中运行rake jasmine.我收到此错误:
hugos-MacBook-Pro:00_hello hugo$ rake jasmine --trace
(in /Users/hugo/Developer/test_first_javascript/learn_javascript)
** Invoke jasmine (first_time)
** Invoke jasmine:server (first_time)
** Invoke jasmine:require (first_time)
** Execute jasmine:require
** Execute jasmine:server
your tests are here:
http://localhost:8888/
rake aborted!
(<unknown>): did not find expected alphabetic or numeric character while scanning an alias at line 5 column 7
/Users/hugo/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych.rb:203:in `parse'
/Users/hugo/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych.rb:203:in `parse_stream'
/Users/hugo/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych.rb:151:in `parse'
/Users/hugo/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych.rb:127:in `load'
/Users/hugo/.rvm/gems/ruby-1.9.3-p194/gems/jasmine-1.2.1/lib/jasmine/config.rb:19:in `simple_config'
/Users/hugo/.rvm/gems/ruby-1.9.3-p194/gems/jasmine-1.2.1/lib/jasmine/config.rb:62:in `spec_dir'
/Users/hugo/.rvm/gems/ruby-1.9.3-p194/gems/jasmine-1.2.1/lib/jasmine/runner_config.rb:32:in `spec_dir'
/Users/hugo/.rvm/gems/ruby-1.9.3-p194/gems/jasmine-1.2.1/lib/jasmine/application.rb:28:in `block (2 levels) in app'
/Users/hugo/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
/Users/hugo/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
/Users/hugo/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:141:in …Run Code Online (Sandbox Code Playgroud) 我有这个lambda:
echo_word = lambda do |words|
puts words
many_words = /\w\s(.+)/
2.times do
sleep 1
match = many_words.match(words)
puts match[1] if match
end
sleep 1
end
Run Code Online (Sandbox Code Playgroud)
我希望将它each作为一个块传递给它,并且将来每个块都会更多.
def is_there_an_echo_in_here *args
args.each &echo_word # throws a name error
end
is_there_an_echo_in_here 'hello out there', 'fun times'
Run Code Online (Sandbox Code Playgroud)
但是当我用这个lambda方法运行my_funky_lambda.rb时,我得到一个NameError.我不确定这个lambda的范围是什么,但我似乎无法访问它is_there_an_echo_in_here.
echo_word如果我使它成为常量ECHO_WORD并使用它就适当地限定和使用,但必须有一个更直接的解决方案.
在这种情况下,echo_word从内部访问lamba 的最佳方法是什么is_there_an_echo_in_here,例如将其包装在模块中,访问全局范围,还有其他什么?