Bhavuk Mathur Bhavuk Mathur - 6 months ago 15
Ruby Question

Undefined method `b64encode' for Base64:Module - Ruby

[![enter image description here][1]][1]

Hi,
I want to encode a string whose length is more than default 60. Therefore, I can't use the Base64.encode64 method.

From the following link - http://ruby-doc.org/stdlib-1.8.7/libdoc/base64/rdoc/Base64.html

I got to know about b64encode(bin, len = 60) method. But on using, it shows the error -

in `<top (required)>': undefined method `b64encode' for Base64:Module (NoMethodError)


Where am I making the mistake.

PS - The version of Ruby for me is
ruby 2.3.0p0

Answer

Base64 has no method b64encode. You are reading the documentation for Ruby 1.8.7, which was released in 2008 and retired in 2013.

The available method for encoding is Base64.encode64.