using System; using Microsoft.Scripting.Hosting; // Create a Ruby engine var engine = IronRuby.Ruby.CreateEngine(); // Get the Ruby context var context = engine.Runtime.Globals; // Retrieve the identifier encoding used in Ruby var identifierEncoding = context.RubyContext.GetIdentifierEncoding(); Console.WriteLine($"Identifier Encoding: {identifierEncoding.EncodingName}");
using System; using System.Text; using Microsoft.Scripting.Hosting; // Create a Ruby engine var engine = IronRuby.Ruby.CreateEngine(); // Get the Ruby context var context = engine.Runtime.Globals; // Set the encoding used for identifiers in Ruby var encoding = Encoding.UTF8; context.RubyContext.SetIdentifierEncoding(encoding); // Retrieve the identifier encoding used in Ruby var identifierEncoding = context.RubyContext.GetIdentifierEncoding(); Console.WriteLine($"Identifier Encoding: {identifierEncoding.EncodingName}");This example sets the character encoding used for identifiers in Ruby scripts to UTF-8 using the `SetIdentifierEncoding` method. The `GetIdentifierEncoding` method is then called to confirm that the encoding was set correctly. These examples use the `IronRuby` package for running Ruby scripts within a C# application.