随笔分类 -  Ruby

摘要:Optional ArgumentsSet default arguments, when we don't need to call it, we can simply skip it.def new_game(name, year=nil, system=nil) { name: nam... 阅读全文
posted @ 2015-11-02 02:52 Zhentiw 编辑
摘要:Installing RSpec In this level we'll start by getting you setup on a regular Ruby project, then move onto using RSpec within Rails. Let's start by ins 阅读全文
posted @ 2014-11-14 23:23 Zhentiw 编辑
摘要:Install RSpec: Describe Lets start writing a specification for the Tweet class. Write a describe block for the Tweet model without any examples inside 阅读全文
posted @ 2014-11-14 22:48 Zhentiw 编辑
摘要:Iterating with BlocksLet's build a Library class that will manage our growing collection of games. We've already written alistmethod that prints the n... 阅读全文
posted @ 2014-09-27 02:59 Zhentiw 编辑
摘要:Using Blocks:words = ['Had', 'eggs', 'for', 'breakfast']for index in 0...(words.length-1) puts words[index]endwords = ['Had', 'eggs', 'for', 'break... 阅读全文
posted @ 2014-09-27 02:52 Zhentiw 编辑
摘要:Read More:http://stackoverflow.com/questions/3066703/blocks-and-yields-in-rubyYes, it is a bit puzzling at first.In Ruby, methods may receive a code b... 阅读全文
posted @ 2014-09-27 01:59 Zhentiw 编辑
摘要:NamespacingCreate a module namedGameUtilsand place thelend_to_friendmethod inside the module. Changelend_to_friendto a class method by prefixing it wi... 阅读全文
posted @ 2014-09-27 01:46 Zhentiw 编辑
摘要:1. Namespace:Ruby可以像Javascript一样定义全局的functions。这些functions都放在global namespace中。容易和之后的method name冲突。我们可以用module来包括这些functions。1. module中的方法需要加self:def ... 阅读全文
posted @ 2014-09-27 01:46 Zhentiw 编辑
摘要:ArraysImplement thelast_gamesmethod below to return the games from the passed index to the end of the list. Try usingArray#fromto return all games sta... 阅读全文
posted @ 2014-09-26 20:48 Zhentiw 编辑
摘要:Collection ClassManaging our game library is getting a little difficult with all of these game instances floating around. Let's create a newLibrarycla... 阅读全文
posted @ 2014-09-26 20:07 Zhentiw 编辑
摘要:Optional ArgumentsWe'll store a little more information about our games than just the name. Optional arguments are important for a flexible interface.... 阅读全文
posted @ 2014-09-20 00:51 Zhentiw 编辑
摘要:Unless to replace if !..?Unless可以理解为"除了"if ! tweets.empty? puts "Timeline:" puts tweetsend//Unless is more intuitiveunless tweets.empty? puts "Ti... 阅读全文
posted @ 2014-09-16 20:14 Zhentiw 编辑
摘要:UnlessWe're putting together a system to manage our vast video game collection that we just can't seem to part with. Usingifwith negative conditions c... 阅读全文
posted @ 2014-09-16 20:04 Zhentiw 编辑

点击右上角即可分享
微信分享提示