On 02/10/2017 02:31 PM, Lukas Ocilka wrote:
On 02/10/2017 02:06 PM, Ancor Gonzalez Sosa wrote:
And all calls to #to_s, #inspect are safe. Even using formatters like pretty_print or awesome_print should be safe.
Ah, and I found one little case where redefining #to_s might cause some problems:
```life When you really want to use it for something else than logging ```
As long as you want to access that value explicitly, #to_s will work
exactly as expected. For example.
class TheClass
include Y2Storage::SecretAttributes
attr_accessor :name
secret_attr :password
end
one_object = TheClass.new
one_object.name = "Aa"
one_object.password = 42
one_object.password # => 42
one_object.password.to_s # => "42"
one_object.send(:password) # => 42
one_object.send(:password).to_s # => "42"
So if you really want to use #to_s for that attribute, it will work with
no surprises.
BUT the class saves you from revealing that value in an indirect way
(i.e. via inspection of the instance attributes). For example:
one_object.to_s
# => "#TheClass:0x000000026bcc98" - This is the default behavior
one_object.inspect
# => "#