草庐IT

Ruby Koans about_array_assignment - 非平行与平行分配歧视

通过ruby​​koans.com,我在about_array_assignment.rb中遇到了这两段代码你怎么知道第一个是非并行赋值,第二个是一个变量的并行赋值?在我看来,除了命名差异之外,代码几乎完全相同。4deftest_non_parallel_assignment5names=["John","Smith"]6assert_equal["John","Smith"],names7end45deftest_parallel_assignment_with_one_variable46first_name,=["John","Smith"]47assert_equal'John

ruby - 我可以在 Ruby 1.9.x 中使用无参数函数吗?

所以我正在研究RubyKoans,而且我遇到了一个我认为是ruby1.9.x特有的问题。deftest_calling_global_methods_without_parenthesesresult=my_global_method2,3assert_equal5,resultend我明白了:james@tristan:~/code/ruby_projects/ruby_koans$rake(in/home/james/code/ruby_projects/ruby_koans)cdkoans/home/james/.rvm/rubies/ruby-1.9.2-p180/bin/ru

ruby - 停留在 EdgeCase Ruby Koans 上的 about_methods.rb

我正在通过EdgeCaseRubyKoans(www.rubykoans.com)进行黑客攻击,并且卡在about_methods.rbhere中从第35行开始的方法上。.运行rake可预见地失败并告诉我查看第36行。我有理由确定我的assert_match是正确的(“0代表2”),但我不知道是什么失败了。assert_raise(___)行很可能应该在括号之间包含一些内容,但我不知道那应该是什么。任何提示或轻推?非常感谢。编辑:这是有问题的代码的一小段:defmy_global_method(a,b)a+bend-剪辑-deftest_calling_global_methods_w

ruby - 2..-1 的范围是什么意思? (Ruby koans about_arrays.rb)

请有人解释一下2..-1的范围对象是什么意思。Rubykoans在about_arrays.rb中有以下内容:deftest_slicing_with_rangesarray=[:peanut,:butter,:and,:jelly]assert_equal[:peanut,:butter,:and],array[0..2]assert_equal[:peanut,:butter],array[0...2]assert_equal[:and,:jelly],array[2..-1]end以下网站(从另一个答案中找到)解释了范围如何与切片一起使用:GaryWright,string/ar

Ruby Koans - 正则表达式和 .sub : Don't understand reason behind answer

为了澄清,这里是about_regular_expressions.rb文件中我遇到问题的确切问题:deftest_sub_is_like_find_and_replaceassert_equal__,"onetwo-three".sub(/(t\w*)/){$1[0,1]}end我知道这个问题的答案是什么,但我不明白得到这个答案是怎么回事。我对Ruby和正则表达式还很陌生,尤其是我对大括号之间的代码以及它如何发挥作用感到困惑。 最佳答案 大括号内的代码是一个blocksub用于替换匹配项:Intheblockform[...]Th

Ruby Koans 与 Ruby 2.0.0 不兼容?

成功升级到Ruby2.0.0的稳定版本后(耶!)我决定继续我的Koans启蒙之路。但是,在koans文件夹中运行rake命令时,就像我通常做的那样,我收到此错误:rakecdkoans/Users/jordanthornquest/.rvm/rubies/ruby-2.0.0-p0/bin/rubypath_to_enlightenment.rb/Users/jordanthornquest/programming/ruby-koans/koans/edgecase.rb:399:in`rescueinmeditate':uninitializedconstantEdgeCase::S

Ruby Koans #75 test_constants_become_symbols,正确答案?

我的问题基于这个问题:RubyKoan:Constantsbecomesymbols.我有以下代码:in_ruby_version("mri")doRubyConstant="Whatisthesoundofonehandclapping?"deftest_constants_become_symbolsall_symbols=Symbol.all_symbolsassert_equal__,all_symbols.include?(__)endend正确答案应该是下面的吗?assert_equaltrue,all_symbols.include?("RubyConstant".to_

ruby - 帮助 Ruby Koans #6 - 捕获了什么异常?

我正在尝试通过Koans学习Ruby,但我卡在了第6步。代码如下:deftest_you_dont_get_null_pointer_errors_when_calling_methods_on_nil#Whathappenswhenyoucallamethodthatdoesn'texist.#Thefollowingbegin/rescue/endcodeblockcapturestheexceptionand#makesomeassertionsaboutit.beginnil.some_method_nil_doesnt_know_aboutrescueException=>e

ruby - 是否有与 ruby​​ koans 项目等效的 Perl?

是否有与ruby-koans等价的Perl项目?当我几个月前开始学习ruby​​时,我偶然发现了ruby​​-koans,它对学习语言的基础知识有很大帮助。我现在需要研究一些Perl代码,虽然我在过去拼凑了一些Perl脚本,但我从未真正学习过这门语言,每次我不得不回顾我为甚至是简单的事情。我有一种感觉,像koans这样的东西会让我更容易学习和保留Perl的知识。有这样的东西吗? 最佳答案 在没有100%相同的替代方案的情况下的两个可能的选择:O'Reilly的PerlCookbook介于perldoc和ruby​​koans之间。.

ruby - Ruby Koans 的 triangle.rb 更优雅的解决方案

我一直在研究RubyKoans并完成了about_triangle_project.rb,您需要在其中编写方法triangle的代码。可在此处找到这些项目的代码:https://github.com/edgecase/ruby_koans/blob/master/koans/about_triangle_project.rbhttps://github.com/edgecase/ruby_koans/blob/master/koans/triangle.rb在triangle.rb中,我创建了以下方法:deftriangle(a,b,c)if((a==b)&&(a==c)&&(b==c