I’m learning Crystal and I’ve trying to use the short-argument syntax (that is explained here) in a custom function that receives a block and an array, and modifes its values. My code is:
numArr = [1, 2, 3, 4, 5]
def modify_elements(arr)
(0...arr.size).each do |i|
arr[i] = yield arr[i]
end
arr
end
modify_elements(numArr) do |arg| # Works
arg.*(10)
end
modify_elements(numArr) &.*(10) # Doesn't work
puts numArr
The compiler throws me this error:
Syntax error in main.cr:16: unexpected token: .
modify_elements(numArr) &.*(10)
^
I can’t understand why that line of code doesn’t work. If anyone can help me, it will be great!