Need to undersatnd the other options with String#encode

Hi,

I found a code online when I was searching a solution to encoding
related

def replace_name(body, name)
  body
    .encode('UTF-8', 'binary', invalid: :replace, undef: :replace,
replace: '')
    .gsub(/joel/, name)
end

Except 'UTF-8', what are the other options are doing ?

Could you tell me what is it doing and when I need to think of this in
real time app?

···

--
Posted via http://www.ruby-forum.com/.

Here is where String#encode is documented:

2.1.x: Class: String (Ruby 2.1.0)
2.0.x: Class: String (Ruby 2.0.0)
1.9.3: Class: String (Ruby 1.9.3)

all describe the options on the method.

···

On Fri, Jan 31, 2014 at 12:54 PM, Arup Rakshit <lists@ruby-forum.com> wrote:

Hi,

I found a code online when I was searching a solution to encoding
related

def replace_name(body, name)
  body
    .encode('UTF-8', 'binary', invalid: :replace, undef: :replace,
replace: '')
    .gsub(/joel/, name)
end

Except 'UTF-8', what are the other options are doing ?

Could you tell me what is it doing and when I need to think of this in
real time app?

--
Posted via http://www.ruby-forum.com/\.