Issue #6733 has been reported by akr (Akira Tanaka). ---------------------------------------- Feature #6733: New inspect framework https://bugs.ruby-lang.org/issues/6733 Author: akr (Akira Tanaka) Status: Open Priority: Normal Assignee: Category: Target version: 3.0 After we discussed http://bugs.ruby-lang.org/issues/6291 at a developer meeting, we re-realized new inspect framework may be useful. Problem: * inspect method may generate too long string but sometimes whole string is not required. For example, first 70 characters are enough for error messages (backtrace). * inspect can't know a encoding to be expected. * inspect generates may short strings and discard them immediately. If we have a new method, inspect_to(buffer), and it (or overridden method in subclass) adds the inspected result to buffer, we can solve above problems. buffer has a method, <<. It may be a string, IO or other object. For too long string, buffer itself can throw (or raise) when buffered output is reached to a specified limit. For encoding, buffer can record an encoding. (p method creates a buffer object using $stdout's encoding.) For small strings, in C level, we can create a rb_buffer_add(VALUE buffer, const char *p, long len) and it don't need to allocate a String object. This is big change but we can preserve compatibility by following default inspect_to method: class Object def inspect_to(buffer) buffer << self.inspect end end If legacy class which has inspect but not inspect_to, Object#inspect_to calls inspect and use the result.
on 2012-07-14 11:06
on 2012-11-18 04:16
Issue #6733 has been updated by boris_stitnicky (Boris Stitnicky).
Thank you so much for this. Whenever I use #inspect and #to_s methods,
such as when writing
puts "blah blah #{object} blah"
I cannot help but be afraid that object's #to_s method will return 20MB
string, that will overrun something somewhere and take control over my
computer :-)
----------------------------------------
Feature #6733: New inspect framework
https://bugs.ruby-lang.org/issues/6733#change-33038
Author: akr (Akira Tanaka)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: Next Major
After we discussed http://bugs.ruby-lang.org/issues/6291 at a developer
meeting,
we re-realized new inspect framework may be useful.
Problem:
* inspect method may generate too long string but sometimes whole string
is not required.
For example, first 70 characters are enough for error messages
(backtrace).
* inspect can't know a encoding to be expected.
* inspect generates may short strings and discard them immediately.
If we have a new method, inspect_to(buffer), and
it (or overridden method in subclass) adds the inspected result to
buffer,
we can solve above problems.
buffer has a method, <<.
It may be a string, IO or other object.
For too long string, buffer itself can throw (or raise) when buffered
output is reached to a specified limit.
For encoding, buffer can record an encoding.
(p method creates a buffer object using $stdout's encoding.)
For small strings, in C level, we can create a rb_buffer_add(VALUE
buffer, const char *p, long len) and
it don't need to allocate a String object.
This is big change but we can preserve compatibility by following
default inspect_to method:
class Object
def inspect_to(buffer)
buffer << self.inspect
end
end
If legacy class which has inspect but not inspect_to,
Object#inspect_to calls inspect and use the result.
on 2012-11-18 04:17
Issue #6733 has been updated by boris_stitnicky (Boris Stitnicky). Call me a paranoid, if you want :-) ---------------------------------------- Feature #6733: New inspect framework https://bugs.ruby-lang.org/issues/6733#change-33039 Author: akr (Akira Tanaka) Status: Open Priority: Normal Assignee: Category: Target version: Next Major After we discussed http://bugs.ruby-lang.org/issues/6291 at a developer meeting, we re-realized new inspect framework may be useful. Problem: * inspect method may generate too long string but sometimes whole string is not required. For example, first 70 characters are enough for error messages (backtrace). * inspect can't know a encoding to be expected. * inspect generates may short strings and discard them immediately. If we have a new method, inspect_to(buffer), and it (or overridden method in subclass) adds the inspected result to buffer, we can solve above problems. buffer has a method, <<. It may be a string, IO or other object. For too long string, buffer itself can throw (or raise) when buffered output is reached to a specified limit. For encoding, buffer can record an encoding. (p method creates a buffer object using $stdout's encoding.) For small strings, in C level, we can create a rb_buffer_add(VALUE buffer, const char *p, long len) and it don't need to allocate a String object. This is big change but we can preserve compatibility by following default inspect_to method: class Object def inspect_to(buffer) buffer << self.inspect end end If legacy class which has inspect but not inspect_to, Object#inspect_to calls inspect and use the result.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.