1
我想向範圍添加一個變量,然後從我的ruby表達式訪問該變量。如何引用從IronRuby添加到ScriptScope的變量?
C#
ScriptRuntime runtime = IronRuby.Ruby.CreateRuntime();
var scope = runtime.ExecuteFile("C:\\codebase\\Test\\Test2\\Test2\\person2.rb");
scope.SetVariable("name", "Scott");
dynamic person = scope.Engine.Execute("p = Person.new(name)");
person.sayHi();
紅寶石
class Person
def initialize(name)
@name = name.capitalize
end
def sayHi
puts "Hello #{@name}!"
end
end
我錯誤地認爲,既然您從範圍調用Execute,那麼它將具有所有必需的範圍。 globalConstants的東西也很酷。這是一種更簡潔的方式來打入紅寶石。 – ScArcher2 2011-03-17 14:10:19