How secure is replacing "to_s" method?

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

SGksIEkndmUgYSBjbGFzcyBsaWtlIHRoaXM6CgpjbGFzcyBSZXF1ZXN0CglhdHRyX2FjY2Vzc29y
IDptZXRob2QsIDpjb2RlCglkZWYgdG9fcwoJCSIje21ldGhvZH0gI3tjb2RlfSIKCWVuZAplbmQK
CgpTbyBpZiBJIHByaW50IGRpcmVjdGx5IGFuIGluc3RhbmNlIEkgc2VlIGEgc3RyaW5nIGNvbnRh
aW5pbmcgYm90aCBhdHRyaWJ1dGVzOgoKbWVzc2FnZSA9IFJlcXVlc3QubmV3Cm1lc3NhZ2UubWV0
aG9kID0gIklOVklURSIKbWVzc2FnZS5jb2RlID0gIjIwMCIKcHV0cyBtZXNzYWdlCj0+ICJJTlZJ
VEUgMjAwIgoKVGhpcyBpcyByZWFsbHkgbmljZSBidXQgSSdtIG5vdCBzdXJlIG9mIGhvdyBzZWN1
cmUgaXQncy4gQ291bGQKcmVwbGFjaW5nICJ0b19zIiBtZXRob2QgY2hhbmdlIGFueSBvdGhlciBi
ZWhhdmlvdXI/CgpUaGFua3MuCgoKCi0tIApJw7Fha2kgQmF6IENhc3RpbGxvCjxpYmNAYWxpYXgu
bmV0Pgo=
 
T

Trans

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 attribut= es:

message =3D Request.new
message.method =3D "INVITE"
message.code =3D "200"
puts message
=3D> "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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,291
Messages
2,571,453
Members
48,131
Latest member
KatlynC08

Latest Threads

Top