I'm trying to do an assignment inside a when-then statement, but it doesn't work as I expected. As I see it, the problem is because, maybe, the case or when-then have a different scope than function. So, how I can reference my variable message_header
to write the correct assignment? Or is other stuff?
def message_notice(type, notice)
message_header = ""
case 'type'
when 'danger' then message_header = 'Oops, something wrong happened'
when 'success' then message_header = 'Done'
when 'warning' then message_header = 'Hey, be careful'
when 'info' then message_header = 'News, news'
end
return "<strong>#{message_header}!</strong> #{notice}"
end