• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

sf-wdi-24/ruby-koans: Students will work on the Ruby Koans site in order to rein ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

sf-wdi-24/ruby-koans

开源软件地址:

https://github.com/sf-wdi-24/ruby-koans

开源编程语言:


开源软件介绍:

Ruby Koans

About Ruby Koans

Each 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 def and end with end -- these reserved words are like the curly brackets of Ruby methods. Also, the class line in each file is a way of organizing the code and grouping the methods together.

Example of completing parts of a koan (from about_hashes.rb):

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

Reference

Reference this reading on Ruby methods for discussion of how the koans' methods are structured.

Exercises

Base Exercises:

cd into your new koans directory and run through the following exercises using ruby <file_name.rb>.

  • About Asserts - about_asserts.rb
  • About Arrays - about_arrays.rb
  • About Nil - about_nil.rb
  • About True and False - about_true_and_false.rb
  • About Strings - about_strings.rb
  • About Methods - about_methods.rb (through method_without_explicit_return)
Stretch Exercises:
  • About Hashes - about_hashes.rb
  • About Blocks - about_blocks.rb
  • About Objects - about_objects.rb
  • About Variable Scope - about_variable_scope.rb
  • About Iteration - about_iteration.rb

Getting started

Fork and clone this repo into your develop directory.

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. cd into the koans directory and run ls. Wow, that's a lot of files!

Submission

Make a pull request when you have completed all of the exercises.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap