Browse Source

added #atRandom at SequenceableCollection

Bernat Romagosa 12 years ago
parent
commit
2f6acca146
3 changed files with 31 additions and 0 deletions
  1. 11 0
      js/Kernel.deploy.js
  2. 16 0
      js/Kernel.js
  3. 4 0
      st/Kernel.st

+ 11 - 0
js/Kernel.deploy.js

@@ -3466,6 +3466,17 @@ return self;}
 }),
 smalltalk.SequenceableCollection);
 
+smalltalk.addMethod(
+'_atRandom',
+smalltalk.method({
+selector: 'atRandom',
+fn: function (){
+var self=this;
+return smalltalk.send(self, "_at_", [smalltalk.send(smalltalk.send(self, "_size", []), "_atRandom", [])]);
+return self;}
+}),
+smalltalk.SequenceableCollection);
+
 
 
 smalltalk.addClass('String', smalltalk.SequenceableCollection, [], 'Kernel');

+ 16 - 0
js/Kernel.js

@@ -4948,6 +4948,22 @@ referencedClasses: []
 }),
 smalltalk.SequenceableCollection);
 
+smalltalk.addMethod(
+unescape('_atRandom'),
+smalltalk.method({
+selector: unescape('atRandom'),
+category: 'accessing',
+fn: function (){
+var self=this;
+return smalltalk.send(self, "_at_", [smalltalk.send(smalltalk.send(self, "_size", []), "_atRandom", [])]);
+return self;},
+args: [],
+source: unescape('atRandom%0A%09%5E%20self%20at%3A%20self%20size%20atRandom'),
+messageSends: ["at:", "atRandom", "size"],
+referencedClasses: []
+}),
+smalltalk.SequenceableCollection);
+
 
 
 smalltalk.addClass('String', smalltalk.SequenceableCollection, [], 'Kernel');

+ 4 - 0
st/Kernel.st

@@ -1676,6 +1676,10 @@ indexOf: anObject startingAt: start
 	within the receiver. If the receiver does not contain anElement, 
 	answer 0."
 	^self indexOf: anObject startingAt: start ifAbsent: [0]
+!
+
+atRandom
+	^ self at: self size atRandom
 ! !
 
 !SequenceableCollection methodsFor: 'adding'!