在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:sf-wdi-24/ruby-koans开源软件地址:https://github.com/sf-wdi-24/ruby-koans开源编程语言:开源软件介绍:Ruby KoansAbout Ruby KoansEach file is a self-contained exercise that will teach you a bit about Ruby, using test driven development. Essentially you will be given code that has something wrong with it, as well as instructions about what needs to be fixed. Then you make the necessary changes for the tests to pass. For example, running this file in the Terminal :> ruby about_hashes.rb will output this: AboutHashes#test_creating_hashes has damaged your karma.
The Master says:
You have not yet reached enlightenment.
The answers you seek...
Expected "FILL ME IN" to equal Hash
Please meditate on the following code:
about_hashes.rb:6:in `test_creating_hashes'
mountains are merely mountains
your path thus far [X_________________________________________________] 0/12 While it may look verbose, all this output is doing is explaining why the code isn't running and stating which line (and which method, if applicable) to fix. Each time a fix is made, the koan will provide a new prompt when the file is run again. Each koan file has some blanks you should fill or lines you should change in to "reach enlightenment" or pass all of the code's tests. Read the comments in a koan file one by one to see what each part should do. If you're unsure what one of the tests is asking for, try a few things, ask in Slack, and skip it if you need to instead of getting stuck. The koan files have some structure we haven't seen yet. Methods are defined by the blocks that start with Example of completing parts of a koan (from require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutHashes < Neo::Koan
def test_creating_hashes
empty_hash = Hash.new
assert_equal Hash, empty_hash.class
assert_equal({}, empty_hash)
assert_equal 0, empty_hash.size
end
def test_hash_literals
hash = { :one => "uno", :two => "dos" }
assert_equal 2, hash.size
end
def test_accessing_hashes
hash = { :one => "uno", :two => "dos" }
assert_equal "uno", hash[:one]
assert_equal "dos", hash[:two]
assert_equal nil, hash[:doesnt_exist]
end
end ReferenceReference this reading on Ruby methods for discussion of how the koans' methods are structured. ExercisesBase Exercises:
Stretch Exercises:
Getting startedFork and clone this repo into your Go to the Ruby Koans website and click the link to download the koans. Open the zip file and save it in your copy of this directory. SubmissionMake a pull request when you have completed all of the exercises. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论