Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Replace a reserved Symbol :_alone instead of :_singleton for Enumerable#chunk #2305

Merged
merged 3 commits into from

5 participants

@kachick
Collaborator

No description provided.

kernel/common/enumerable19.rb
((6 lines not shown))
yielder.yield [key, [val]]
else
- raise RuntimeError, "symbol beginning with an underscore are reserved"
+ raise RuntimeError, "symbol begins with an underscore is reserved"
@leocassarani Collaborator

I'm not sure we should be making our exception strings ungrammatical in the name of matching what MRI does. Can we simply fix the typo in the original sentence and leave it as "symbols beginning with an underscore are reserved"?

P.S. I realise English may not be your first language, so apologies if this comes across overly critical.

@jc00ke Owner
jc00ke added a note

I was just about to make the same comment. I don't think we should be matching MRI here.

@kachick Collaborator
kachick added a note

Thank you for letting me know!
I'll remove this commit.

@leocassarani Collaborator

Could you go one step further and add an "s" to the end of "symbol"? As in, "symbols beginning with...". You can amend the original commit if you like.

@kachick Collaborator
kachick added a note

Sure.

@agrimm
agrimm added a note

In future, when fixing grammar like this, it may be worthwhile suggesting the same edit to MRI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dbussink dbussink merged commit 93408f4 into from
@kachick kachick deleted the branch
@agrimm

Are you a time traveller? I filed a bug report for this with YARV on May 1. :astonished:

Collaborator

No.
I think "John Titor" is @leocassarani. :smile:

rubinius#2305 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
4 kernel/common/enumerable19.rb
@@ -15,10 +15,10 @@ def chunk(initial_state = nil, &original_block)
previous = nil
case key
when nil, :_separator
- when :_singleton
+ when :_alone
yielder.yield [key, [val]]
else
- raise RuntimeError, "symbol beginning with an underscore are reserved"
+ raise RuntimeError, "symbols beginning with an underscore are reserved"
end
else
if previous.nil? || previous == key
View
36 spec/ruby/core/enumerable/chunk_spec.rb
@@ -40,5 +40,41 @@
ret[3].last.should == [1]
ret[4].last.should == [9]
end
+
+ it "sets a 2-element Array if the block returned :_alone" do
+ ret = EnumerableSpecs::Numerous.new(5,5,2,3,4,5,7,1,9).chunk {|e| e <= 3 && :_alone }.to_a
+ ret.should == [
+ [false, [5, 5]],
+ [:_alone, [2]],
+ [:_alone, [3]],
+ [false, [4, 5, 7]],
+ [:_alone, [1]],
+ [false, [9]]
+ ]
+ end
+
+ it "rejects 2-element Arrays if the block returned nil" do
+ ret = EnumerableSpecs::Numerous.new(5,5,2,3,4,5,7,1,9).chunk {|e| e <= 3 && nil }.to_a
+ ret.should == [
+ [false, [5, 5]],
+ [false, [4, 5, 7]],
+ [false, [9]]
+ ]
+ end
+
+ it "rejects 2-element Arrays if the block returned :_separator" do
+ ret = EnumerableSpecs::Numerous.new(5,5,2,3,4,5,7,1,9).chunk {|e| e <= 3 && :_separator }.to_a
+ ret.should == [
+ [false, [5, 5]],
+ [false, [4, 5, 7]],
+ [false, [9]]
+ ]
+ end
+
+ it "raises an RuntimeError if the block returned a Symbol that is undefined but reserved format (first character is an underscore)" do
+ lambda {
+ EnumerableSpecs::Numerous.new(5,5,2,3,4,5,7,1,9).chunk {|e| e <= 3 && :_singleton }.to_a
+ }.should raise_error(RuntimeError)
+ end
end
end
Something went wrong with that request. Please try again.