Copying this code from book Programming Ruby and running it in rubyfiddle.com . Getting syntax error instead of # => 21 ? Any help is appreciated!
arr = [ 1, 1, 2, 3, 5, 8, 13, 21, 34 ]
res = arr.bsearch do |val|
case
when val < 19 then +1
when val > 23 then -1
else 0
end
end
res # => 21