Skip to content

Commit 0f44fd5

Browse files
committed
Add missing file
1 parent c1c7791 commit 0f44fd5

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Refines basic operations like operators and element access,
2+
# including Hash#[] with a String key, so specs can check
3+
# the specialized call paths implementations use for them.
4+
# Do this in a subprocess to not disable optimizations globally for the main process.
5+
module Operators
6+
refine Integer do
7+
def +(other)
8+
"plus(#{self},#{other})"
9+
end
10+
11+
def <(other)
12+
"lt"
13+
end
14+
end
15+
16+
refine Array do
17+
def [](i)
18+
"at#{i}"
19+
end
20+
end
21+
22+
refine Hash do
23+
def [](k)
24+
"aref(#{k})"
25+
end
26+
end
27+
end
28+
29+
refined = -> a, b { [a + b, a < b] }.refined(Operators)
30+
puts refined.call(1, 2)
31+
puts -> a { a[0] }.refined(Operators).call([9])
32+
puts -> h { h["x"] }.refined(Operators).call({ "x" => 1 })
33+
puts -> a, b { a + b }.call(1, 2)

0 commit comments

Comments
 (0)