Method: Base64.b64encode
- Defined in:
- lib/base64.rb
.b64encode(bin, len = 60) ⇒ Object
Prints the Base64 encoded version of bin (a String) in lines of len (default 60) characters.
require 'base64'
data = "Now is the time for all good coders\nto learn Ruby"
Base64.b64encode(data)
Generates:
Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
UnVieQ==
112 113 114 115 116 |
# File 'lib/base64.rb', line 112 def b64encode(bin, len = 60) encode64(bin).scan(/.{1,#{len}}/) do print $&, "\n" end end |