Chinaunix首页 | 论坛 | 博客
  • 博客访问: 589832
  • 博文数量: 207
  • 博客积分: 10128
  • 博客等级: 上将
  • 技术积分: 2440
  • 用 户 组: 普通用户
  • 注册时间: 2004-10-10 21:40
文章分类

全部博文(207)

文章存档

2009年(200)

2008年(7)

我的朋友

分类:

2009-04-08 15:24:42

When you're planning a party, do you ? Does it make sense to pick up the food from the caterer before you've booked a the rec hall? Once you've booked that rec hall, though, how do you remember the address to give to the caterer? In its simplified form, a computer program can be thought of as a structured "To-Do" list. Each thing on the list needs to be completed to accomplish a final task, but also needs to done in a certain order.

If your computer program is your party list, than variables are the sticky notes you use to keep track of all the data you've collected. Without your sticky notes, you'd be at a loss as to how to move forward with planning. Without , your Ruby program isn't able to keep track of its data either.

Feature Number Two:

Programs often have to manage collections of variables. Take for example, a program that manages your party information. You're bound to have party guests, each of whom must be stored in a variable and a list of which can be stored together in an array variable. That way you can access each guest via the .

Feature Number Three:

Now imagine your party is a potluck event and each guest is required to bring a dish or other item. You'll still need a list of guests, which can be managed as an array, but you'll also need a way to keep track of what types of food are being brought. Additionally, you'll probably want to know who is bringing what. Using a hash to store pairs allows you to store that information. Say Susan is bringing chocolate cake to your party. The "key" will be "Susan" and the variable stored and accessed by the key (the value) will be "chocolate cake."

Feature Number Four:

Computer programs often have to perform actions more than just once. For example, if your program prints all new information added to your pot luck list, it will need to print more than just a single time. This can be accomplished using a construct known as a .

Feature Number Five:

Blocks aren't anything new, especially to functional programmers. In Ruby, the use of these nameless is widespread and the block is one of the language's key features. They're often used to abstract the more tedious and repetitive loops into a more user-friendly forms.
阅读(877) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2011-08-11 03:19:15

Thanks. Indeed these are important features. Some examples on the same blog would be helpful too. Some nice examples can be found here on ruby hash.