-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce metaclass/new/allocate/initialize to better match Ruby.
- Loading branch information
Showing
15 changed files
with
393 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
public abstract class RClass extends RObject { | ||
protected final RString name; | ||
|
||
public RClass(String name) { | ||
this.name = new RString(name); | ||
} | ||
|
||
public String toString() { | ||
return name.toString(); | ||
} | ||
|
||
public RObject to_s() { | ||
return name; | ||
} | ||
|
||
public RObject $new(RObject... args) { | ||
RObject object = allocate(); | ||
object.initialize(args); | ||
return object; | ||
} | ||
|
||
public RObject $new() { | ||
RObject object = allocate(); | ||
object.initialize(); | ||
return object; | ||
} | ||
|
||
public RObject $new(RObject arg) { | ||
RObject object = allocate(); | ||
object.initialize(arg); | ||
return object; | ||
} | ||
|
||
public RObject allocate() { | ||
throw new RuntimeException("not allocatable: " + name); | ||
} | ||
|
||
public RObject name() { | ||
return new RString(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
public class RNil extends RObject { | ||
public static class NilMeta extends RClass { | ||
public NilMeta(String name) { | ||
super(name); | ||
} | ||
|
||
public NilMeta() { | ||
super("NilClass"); | ||
} | ||
} | ||
|
||
public RClass $class() { | ||
return NilClass; | ||
} | ||
|
||
@Override | ||
public RString to_s() { | ||
return new RString("nil"); | ||
} | ||
|
||
public RFixnum to_i() { | ||
return new RFixnum(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.