Skip to content

Commit 245279f

Browse files
committed
[Truffle] - Adds Random class
1 parent 5a506d2 commit 245279f

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

spec/truffle/tags/core/random/new_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
fails:Random.new returns a new instance of Random
21
fails:Random.new uses a random seed value if none is supplied
32
fails:Random.new returns Random instances initialized with different seeds
43
fails:Random.new accepts an Integer seed value as an argument

truffle/src/main/java/org/jruby/truffle/nodes/RubyTypes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
RubyEncoding.class, //
5454
RubySymbol.class, //
5555
RubyThread.class, //
56-
RubyTime.class, //
56+
RubyTime.class,
57+
RubyRandom.class, //
5758
RubyEncodingConverter.class, //
5859
RubyMethod.class, //
5960
RubyUnboundMethod.class, //
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.jruby.truffle.nodes.core;
2+
3+
@CoreClass(name = "Random")
4+
public abstract class RandomNodes {
5+
6+
}

truffle/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public class CoreLibrary {
9898
private final RubyClass securityErrorClass;
9999
private final RubyClass standardErrorClass;
100100
private final RubyClass stringClass;
101+
private final RubyClass randomClass;
101102
private final RubyClass stringDataClass;
102103
private final RubyClass symbolClass;
103104
private final RubyClass syntaxErrorClass;
@@ -284,6 +285,7 @@ public CoreLibrary(RubyContext context) {
284285
rangeClass = defineClass("Range", new RubyRange.RangeAllocator());
285286
regexpClass = defineClass("Regexp", new RubyRegexp.RegexpAllocator());
286287
stringClass = defineClass("String", new RubyString.StringAllocator());
288+
randomClass = defineClass("Random");
287289
symbolClass = defineClass("Symbol");
288290
threadClass = defineClass("Thread", new RubyThread.ThreadAllocator());
289291
timeClass = defineClass("Time", new RubyTime.TimeAllocator());
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.jruby.truffle.runtime.core;
2+
3+
/**
4+
* Represents the Ruby {@code Random} class.
5+
*/
6+
public class RubyRandom extends RubyBasicObject {
7+
8+
private Long seedValue;
9+
10+
public RubyRandom(RubyClass randomClass) {
11+
super(randomClass);
12+
}
13+
14+
public void setSeedValue(Long seedValue) {
15+
this.seedValue = seedValue;
16+
}
17+
18+
}

0 commit comments

Comments
 (0)