From: "bkuhlmann (Brooke Kuhlmann) via ruby-core" Date: 2026-10-14T22:52:17+00:00 Subject: [ruby-core:127112] [Ruby Feature#22443] Remove multi-line regular expression comments from object inspection Issue #22443 has been reported by bkuhlmann (Brooke Kuhlmann). ---------------------------------------- Feature #22443: Remove multi-line regular expression comments from object inspection https://bugs.ruby-lang.org/issues/22443 * Author: bkuhlmann (Brooke Kuhlmann) * Status: Open ---------------------------------------- ## Why Hello. ���� Would it be possible to remove multi-line regular expression comments from object inspection? For example, this is nice for readability via the source code: ``` ruby class Demo PATTERN = / (?: # Start non-capture group. (?[0-9]+) # Position capture group, numbers only. - # Dash. )? # End non-capture group and make it optional. (?[[:word:]-]+) # Name capture group, required. (?: # Non-capture group start. \+ # Plus. (?[[:word:]\-,=]+) # Meta capture group, required. )? # End non-capture group and make it optional. /x def initialize pattern = PATTERN @pattern = pattern end private attr_reader :pattern end ``` However, the above is quite noisy when inspecting the object. Example: ``` ruby Demo.new #[0-9]+) # Position capture group, numbers only. - # Dash. )? # End non-capture group and make it optional. (?[[:word:]-]+) # Name capture group, required. (?: # Non-capture group start. \+ # Plus. (?[[:word:]\-,=]+) # Meta capture group, required. )? # End non-capture group and make it optional. /x> ``` ## How It would be nice to automatically strip the comments and collapse the newlines for the object when inspecting it. Example: ``` ruby Demo.new #[0-9]+)-)?(?[[:word:]-]+)(?:\+(?[[:word:]\-,=]+))?/> ``` The above frees up a lot of vertical space -- especially when inspecting multiple objects at once -- so you don't have to scroll so much via the command line. You still get a visual indication that a pattern is used and can jump to the source if you need readability to learn more. ## Notes One solution to the above is to add this private method: ``` def instance_variables_to_inspect = %i[@pattern] ``` The above definitely reduces the verbosity but at the cost of hiding the instance variable. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/