Permalink
Browse files

Array#pop should check frozen even when empty (as per rubyspec). Also…

… update other fixes to use existing implementation of RequireNotFrozen(IList) instead of manually casting
  • Loading branch information...
Orion Edwards [GGL]
Orion Edwards [GGL] committed Jan 5, 2012
1 parent 62f936c commit a1ec97cfc2769ce495b824942181921daa64d294
Showing with 5 additions and 13 deletions.
  1. +5 −13 Languages/Ruby/Libraries/Extensions/IListOps.cs
@@ -41,7 +41,7 @@ public static class IListOps {
private static void RequireNotFrozen(IList/*!*/ self) {
RubyArray array = self as RubyArray;
if (array != null && array.IsFrozen) {
- throw RubyExceptions.CreateObjectFrozenError();
+ throw RubyExceptions.CreateArrayFrozenError();
}
}
@@ -1725,6 +1725,7 @@ public static class IListOps {
[RubyMethod("pop")]
public static object Pop(IList/*!*/ self) {
+ RequireNotFrozen(self);
if (self.Count == 0) {
return null;
}
@@ -1756,11 +1757,7 @@ public static class IListOps {
[RubyMethod("shift")]
public static object Shift(IList/*!*/ self) {
- var rubyArray = self as RubyArray;
- if (rubyArray != null) {
- rubyArray.RequireNotFrozen();
- }
-
+ RequireNotFrozen(self);
if (self.Count == 0) {
return null;
}
@@ -1776,10 +1773,7 @@ public static class IListOps {
throw RubyExceptions.CreateArgumentError("negative array size");
}
- var rubyArray = self as RubyArray;
- if (rubyArray != null) {
- rubyArray.RequireNotFrozen();
- }
+ RequireNotFrozen(self);
IList resultList = CreateResultArray(allocateStorage, self);
@@ -2006,9 +2000,7 @@ public static class IListOps {
[RubyMethod("rotate!")]
public static IList/*!*/ InPlaceRotate(IList/*!*/ self, [DefaultProtocol]int n) {
- if (self is RubyArray) {
- ((RubyArray)self).RequireNotFrozen(); // check frozen first, for consistency with shuffle, fill, etc
- }
+ RequireNotFrozen(self);
var count = self.Count;
if (count == 0 || count == 1)

0 comments on commit a1ec97c

Please sign in to comment.