[Ironruby-core] How to fire IronRuby Method from C#

Curt Hagenlocher curth at microsoft.com
Wed Jun 10 13:38:12 EDT 2009


Odd. It works for me.  Here's my complete code:

namespace ConsoleApplication2 {
    class Program {
        static void Main(string[] args) {
            var engine = IronRuby.Ruby.CreateEngine();

            engine.Execute(@"
class Person
  def greet()
    puts 'hello world'
  end
end
");

            object personClass = engine.Runtime.Globals.GetVariable("Person");
            dynamic person = engine.Operations.CreateInstance(personClass);
            person.greet();
            System.Console.ReadLine();
        }
    }
}

-----Original Message-----
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Mohammad Azam
Sent: Tuesday, June 09, 2009 8:37 PM
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] How to fire IronRuby Method from C#

Curt Hagenlocher wrote:
> Yes, sorry, you're right -- it's Engine.Operations (but the name of the 
> class is "ObjectOperations").
> 
> The error message tells you exactly what you need to do! Make sure 
> you've added references to Microsoft.CSharp.dll and System.Core.dll to 
> your project.

The error is now gone! but I got the new error which says:

RubyObject does not contain the definition for greet!

   object personClass = engine.Runtime.Globals.GetVariable("Person");
            dynamic person = 
engine.Operations.CreateInstance(personClass);

            person.greet();

-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ironruby-core mailing list
Ironruby-core at rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core



More information about the Ironruby-core mailing list