Bug #4359
closedregular expressions created with Regexp::FIXEDENCODING have incorrect inspect
Description
=begin
irb(main):001:0> x = //
=> //
irb(main):002:0> y = Regexp.new('', Regexp::FIXEDENCODING)
=> //
irb(main):003:0> [x.inspect, y.inspect]
=> ["//", "//"]
irb(main):004:0> [x.options, y.options]
=> [0, 16]
irb(main):005:0>
=end
Updated by naruse (Yui NARUSE) over 14 years ago
- Status changed from Open to Feedback
=begin
I don't think we must show Regexp#fixed_encoding? in Regexp#inspect.
=end
Updated by tenderlovemaking (Aaron Patterson) over 14 years ago
=begin
On Tue, Feb 15, 2011 at 04:23:24PM +0900, Yui NARUSE wrote:
Issue #4359 has been updated by Yui NARUSE.
Status changed from Open to Feedback
I don't think we must show Regexp#fixed_encoding? in Regexp#inspect.
The problem is that Regexp#inspect is used for YAML dumping and loading:
irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> y = Regexp.new('', Regexp::FIXEDENCODING)
=> //
irb(main):003:0> x = YAML.load YAML.dump y
=> //
irb(main):004:0> x.options
=> 0
irb(main):005:0> y.options
=> 16
irb(main):006:0> YAML.dump y
=> "--- !ruby/regexp //\n"
irb(main):007:0>
I suppose I could add a special case, but that seems strange. It also
seems strange that inspect will not allow us to differentiate between
regular expressions with different options.
--
Aaron Patterson
http://tenderlovemaking.com/
Attachment: (unnamed)
=end
Updated by naruse (Yui NARUSE) over 14 years ago
- Status changed from Feedback to Rejected
=begin
I suppose I could add a special case, but that seems strange. It also
seems strange that inspect will not allow us to differentiate between
regular expressions with different options.
inspect shows only essential information and for human readings.
The usage for machine processing is wrong way.
(The practical problem is Regexp#inspect provides the output like a regexp literal but there is no general syntax for fixed_encoding)
What is Object#inspect is arguable point but I think it is what provides the output for p method or irb.
see also http://redmine.ruby-lang.org/issues/show/735
=end