コード例 #1
0
func SetupLoadPathWithAFileToRequire(vm vm.VM) {
	tempPath, err := ioutil.TempDir("", "")
	if err != nil {
		panic(err)
	}

	err = ioutil.WriteFile(filepath.Join(tempPath, "foo.rb"), []byte(`
def foo

FOO_CONST = 'foo'

end
`), 0600)

	if err != nil {
		panic(err)
	}

	loadPathGlobal, err := vm.Get("LOAD_PATH")
	if err != nil {
		panic(err)
	}

	loadPathGlobal.(*builtins.Array).Append(builtins.NewString(tempPath, vm))
}
コード例 #2
0
func SetupFileWithGlobalFilenameConst(vm vm.VM) {
	tempPath, err := ioutil.TempDir("", "")
	if err != nil {
		panic(err)
	}

	err = ioutil.WriteFile(filepath.Join(tempPath, "foo.rb"), []byte("foo = __FILE__"), 0600)

	if err != nil {
		panic(err)
	}

	loadPathGlobal, err := vm.Get("LOAD_PATH")
	if err != nil {
		panic(err)
	}

	loadPathGlobal.(*builtins.Array).Append(builtins.NewString(tempPath, vm))
}