How secure is replacing "to_s" method?

Hi, I’ve a class like this:

class Request
attr_accessor :method, :code
def to_s
“#{method} #{code}”
end
end

So if I print directly an instance I see a string containing both
attributes:

message = Request.new
message.method = “INVITE”
message.code = “200”
puts message
=> “INVITE 200”

This is really nice but I’m not sure of how secure it’s. Could
replacing “to_s” method change any other behaviour?

Thanks.

On Apr 24, 9:04 am, “Iñaki Baz C.” [email protected] wrote:

message = Request.new
message.method = “INVITE”
message.code = “200”
puts message
=> “INVITE 200”

This is really nice but I’m not sure of how secure it’s. Could
replacing “to_s” method change any other behaviour?

It’s fine for your own classes.

T.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs