Re: [問題] 一個 State transitions for bollean r …
※ 引述《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
推
11/12 14:52, , 1F
11/12 14:52, 1F
→
11/12 14:52, , 2F
11/12 14:52, 2F
推
11/12 15:03, , 3F
11/12 15:03, 3F
→
11/12 15:09, , 4F
11/12 15:09, 4F
Ruby 近期熱門文章
PTT數位生活區 即時熱門文章