
with Comprehension::DSL do
assert_equal(
[1, 2, 3],
list {x + 1 }.given(:x => 0..2) )
assert_equal(
[[0, :a], [0, :b], [1, :a], [1, :b]],
list {[x, y] }.given(:x => [0, 1], :y => [:a, :b]) )
assert_equal(
[2, 4, 6, 8, 10],
list {x }.given(:x => 1..10) {x % 2 == 0 } )
end
end
num
num + 7
end
num
lambda {x * num }
end
two = 2
triple = times_maker(3)
with Comprehension::DSL do
assert_equal(
[2, 4, 6],
list {x * two }.given(:x => 1..3) )
assert_equal(
[3, 6, 9],
list(&triple).given(:x => 1..3) )
assert_equal(
[8, 9, 10],
list {plus_seven(x) }.given(:x => 1..3) )
end
end
end
Labels: ruby