File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -165,7 +165,13 @@ def initialize(pattern, options = '')
165165 #
166166 # @since 3.1.0
167167 def respond_to? ( method , include_private = false )
168- compile . respond_to? ( method , include_private ) || super
168+ if defined? ( @pattern )
169+ compile . respond_to? ( method , include_private ) || super
170+ else
171+ # YAML calls #respond_to? during deserialization, before the object
172+ # is initialized.
173+ super
174+ end
169175 end
170176
171177 # Encode the Raw Regexp object to BSON.
Original file line number Diff line number Diff line change 580580 end
581581 end
582582 end
583- end
583+
584+ describe 'yaml loading' do
585+ let ( :regexp ) { described_class . new ( 'hello.world' , 's' ) }
586+
587+ it 'round-trips' do
588+ actual = YAML . load ( regexp . to_yaml )
589+ actual . pattern . should == 'hello.world'
590+ actual . options . should == 's'
591+ actual . compile . should =~ "hello\n world"
592+ end
593+ end
594+ end
You can’t perform that action at this time.
0 commit comments