Please help me understand the difference between range operators ...and ..how the “triggers” used in Ruby.
This is an example Pragmatic Programmers manual for Ruby:
a = (11..20).collect {|i| (i%4 == 0)..(i%3 == 0) ? i : nil}
which returns:
[nil, 12, nil, nil, nil, 16, 17, 18, nil, 20]
also:
a = (11..20).collect {|i| (i%4 == 0)...(i%3 == 0) ? i : nil}
returned:
[nil, 12, 13, 14, 15, 16, 17, 18, nil, 20]
source
share