Hi
I have some ruby code, which through a process of instance_eval and
other
meta programming tricks builds an object with a method assign defined on
it.
I have this code in C#
var scope = Engine.CreateScope();
scope.SetVariable(“ctxt”, this);
Engine.ExecuteFile(“rubyfile.rb”, scope);
This code correctly sets a something property on this (linked with ctxt)
but when I then want to call a method on it that should exist
public dynamic Something { get; set; }
Something.assign(“ivan”)
Unhandled Exception:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:
‘Iro
nRuby.Builtins.RubyObject’ does not contain a definition for ‘assign’
at CallSite.Target(Closure , CallSite , Object , String )
at
System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite
site,
T0 arg0, T1 arg1)
at BugTracker_40.Bug.Assign(String assignee) in
C:\dev\ironruby-in-action\Sam
ples\BugTracker_40\BugTracker_40\Bug.cs:line 60
at BugTracker_40.Program.Main(String[] args) in
C:\dev\ironruby-in-action\Sam
ples\BugTracker_40\BugTracker_40\Program.cs:line 13
However the same code with:
var _rubyOperations = Engine.CreateOperations()
public object Something { get; set; }
_rubyOperations.InvokeMember(Something, “assign”, “ivan”)
does work.
The question is why? Is this the expected behavior? Am I missing an
assembly
reference (it has Ironruby.*, Microsoft.Scripting,
Microsoft.Scripting.Core)
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Google Wave: [email protected]
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)