《guide to ruby》读书笔记1
1、ruby有三种变量:
Global variables can be used anywhere in your program. They never go out of sight.以$开头
Instance variables,以@开头
Class variables,以@@开头
2、布尔值
The?unless
?keyword has a policy of?only allowing those with a negative charge in. Who are:?nil
?and?false
.
?And another nice trick: stack the?
if
?and?unless
.This trick is a gorgeous way of expressing,?Do this only if?a* is true and *b?isn’t true.
?3、循环
When you are iterating through a list, you may use?
next
?toskip on to the next itemcase year when 1894 "Born." when 1895..1913 "Childhood in Lousville, Winston Co., Mississippi." else "No information about this year." endif 1894 === year "Born." elsif 1895..1913 === year "Childhood in Lousville, Winston Co., Mississippi." else "No information about this year." end?Take the Ranges above.?
(1895..1913)
?isn’t at all?equal?to?1905
. No, the Range?(1895..1913)
?is only truly?equal?to any other Range?(1895..1913)
.