r = "FBFB".split("").map do |char|
if char == "F"
return 1
end
if char == "B"
return 2
end
end
puts r.inspect
I get nothing printed to console. What am I doing wrong?
Turns out you cannot use return inside of a code block, but you should use next (source).
next here. Could, but shouldn't. I'd personally do what's described in zswqa's answer.next in this case), the body will always be executed in full and return the value of the last evaluated expression. That's what I call "one exit point". Always the last expression. And yes, that is precisely why I like that code.next here works, even if it isn't idiomatic ruby.
returnand correct if-else statement