Skip to content

Commit ffa628e

Browse files
committedMay 24, 2015
Merge pull request #3408 from rubinius/regex-new-2959
Regex new 2959
2 parents 73e862e + a60dfb3 commit ffa628e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
 

Diff for: ‎kernel/common/regexp.rb

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ def initialize(pattern, opts=nil, lang=nil)
128128
if pattern.kind_of?(Regexp)
129129
opts = pattern.options
130130
pattern = pattern.source
131+
elsif pattern.kind_of?(Fixnum) or pattern.kind_of?(Float)
132+
raise TypeError, "can't convert Fixnum into String"
131133
elsif opts.kind_of?(Fixnum)
132134
opts = opts & (OPTION_MASK | KCODE_MASK) if opts > 0
133135
elsif opts

Diff for: ‎spec/ruby/core/regexp/new_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@
1616
it_behaves_like :regexp_new_regexp_ascii, :new
1717
it_behaves_like :regexp_new_regexp_ascii_8bit, :new
1818
end
19+
20+
describe "Regexp.new given a Fixnum" do
21+
it "raises a TypeError" do
22+
lambda { Regexp.new(1) }.should raise_error(TypeError)
23+
end
24+
end
25+
26+
describe "Regexp.new given a Float" do
27+
it "raises a TypeError" do
28+
lambda { Regexp.new(1.0) }.should raise_error(TypeError)
29+
end
30+
end

0 commit comments

Comments
 (0)