The function above is adapted from vim-ruby plugin.