1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/base64] Simplify

Thanks @nobu!

39e22efa2b
This commit is contained in:
Joao Fernandes 2021-09-02 16:57:26 +01:00 committed by Hiroshi SHIBATA
parent 05a28ce5b1
commit 1b004ba0db

View file

@ -82,13 +82,7 @@ module Base64
# You can remove the padding by setting +padding+ as false.
def urlsafe_encode64(bin, padding: true)
str = strict_encode64(bin)
unless padding
if str.end_with?("==")
str.delete_suffix!("==")
elsif str.end_with?("=")
str.chop!
end
end
str.chomp!("==") or str.chomp!("=") unless padding
str.tr!("+/", "-_")
str
end