Skip to content

Loading…

Range#each should raise a TypeError if the first element is a Time object #699

Merged
merged 1 commit into from

2 participants

@atambo
JRuby Team member

No description provided.

@headius headius merged commit ec393a4 into jruby:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 3 additions and 2 deletions.
  1. +0 −1 spec/tags/1.9/ruby/core/range/each_tags.txt
  2. +3 −1 src/org/jruby/RubyRange.java
View
1 spec/tags/1.9/ruby/core/range/each_tags.txt
@@ -1 +0,0 @@
-fails:Range#each raises a TypeError if the first element is a Time object
View
4 src/org/jruby/RubyRange.java
@@ -453,7 +453,9 @@ public IRubyObject each19(final ThreadContext context, final Block block) {
Ruby runtime = context.runtime;
if (!block.isGiven()) return enumeratorize(runtime, this, "each");
- if (begin instanceof RubyFixnum && end instanceof RubyFixnum) {
+ if (begin instanceof RubyTime) {
+ throw runtime.newTypeError("can't iterate from Time");
+ } else if (begin instanceof RubyFixnum && end instanceof RubyFixnum) {
fixnumEach(context, runtime, block);
} else if (begin instanceof RubyString) {
((RubyString) begin).uptoCommon19(context, end, isExclusive, block);
Something went wrong with that request. Please try again.