作者contagious (布谷饱吃不堡)
看板Ruby
标题Re: [问题] 一个 State transitions for bollean r …
时间Sun Nov 12 10:59:28 2006
※ 引述《fuha (mimi)》之铭言:
: 小弟现在正在看 programming ruby , 看到一章 expressions 的问题
: 如果有书的人,可以看看 p.327页
: 书上是要解释 Ranges in Bollean Expression
: 他也有一个状态图可以看 如下
: expr1 is true
: ------------>------ if expr2 is false
: | | --------
: start -> unset -- -- set <-------|
: | | | expr2 is true |
: | | ----<---------------
: |<--|
: expr1 is false
把整个流程写出来就懂了
: 我的问题是,我怎麽也看不懂他举的例子..如下
: a = (11..20).collect { |i| (i%4 == 0)..(i%3 == 0) ?i : nil}
11 11%4 != 0 => unset
12 12%4 == 0 => set, output 12, 12%3 == 0 => unset
13 13%4 != 0 => unset
14 14%4 != 0 => unset
15 15%4 != 0 => unset
16 16%4 == 0 => set, output 16, 16%3 != 0 => set
17 output 17, 17%3 != 0 => set
18 output 18, 18%3 == 0 => unset
19 19%4 != 0 => unset
20 20%4 == 0 => set, output 20, 20%3 != 0 => unset
: 与
: a = (11..20).collect { |i| (i%4 == 0)...(i%3 == 0) ?i : nil}
11 11%4 != 0 => unset
12 12%4 == 0 => set, output 12
13 output 13, 13%3 != 0 => set
14 output 14, 14%3 != 0 => set
15 output 15, 15%3 == 0 => unset
16 16%4 == 0 => set, output 16,
17 output 17, 17%3 != 0 => set
18 output 18, 18%3 == 0 => unset
19 19%4 != 0 => unset
20 20%4 == 0 => set, output 20
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.115.161.115
1F:推 godfat:不过我倒是想问,这种在哪里用得到?一时想不太到 11/12 14:52
2F:→ godfat: ^/机制\ 11/12 14:52
3F:推 fuha:很奇怪的应用.....ˋ(′_‵||)ˊ 11/12 15:03
4F:→ fuha: 说错了...应该是很奇怪的机制 不过我po的文章里 推文里的连 11/12 15:09