I have two strings:
short_string = "hello world"
long_string = "this is a very long long long .... string" # suppose more than 10000 chars
I want to change the default behavior of print
to:
puts short_string
# => "hello world"
puts long_string
# => "this is a very long long....."
The long_string
is only partially printed. I tried to change String#to_s
, but it didn't work. Does anyone know how to do it like this?
updated
Actually i wanna it works smoothly, that means the following cases also work fine:
> puts very_long_str
> puts [very_long_str]
> puts {:a => very_long_str}
So i think the behavior belongs to String.
Thanks all anyway.
string.length > max ? "#{string[0...(max-3)]}..." : string
, maybe – Dongdonga