Initialize file methods after file lib is required.
@@ -11,7 +11,7 @@ var fileClass *RClass
func initializeFileClass(vm *VM) {
class := initializeClass("File", false)
- class.setBuiltInMethods(builtinFileClassMethods, true)
+ class.setBuiltInMethods(builtinFileClassMethods(), true)
vm.constants["File"] = &Pointer{Target: class}
fileClass = class
}
@@ -38,7 +38,9 @@ var fileModeTable = map[string]int{
"w+": syscall.O_RDWR,
}
-var builtinFileClassMethods = []*BuiltInMethodObject{
+// Only initialize file related methods after it's being required.
+func builtinFileClassMethods() []*BuiltInMethodObject{
+ return []*BuiltInMethodObject{
{
// Finds the file with given filename and initializes a file object with it.
//
@@ -222,3 +224,5 @@ var builtinFileClassMethods = []*BuiltInMethodObject{
},
},
}
+
+}
