// Open a file and read its content using RubyIO using IronRuby.Builtins; var filename = "example.txt"; var content = ""; var file = RubyIO.OpenFile(filename, "r"); if (!file.IsNull) { content = file.Read(); file.Close(); } Console.WriteLine(content);
// Open a file and write to it using RubyIO using IronRuby.Builtins; var filename = "example.txt"; var content = "This is a sample text"; var file = RubyIO.OpenFile(filename, "w"); if (!file.IsNull) { file.Write(content); file.Close(); } Console.WriteLine("File written successfully.");In this example, the OpenFile method is used to open a file for writing and its Write method to write the text into it. The file is again closed using its Close method. Overall, IronRuby.Builtins RubyIO is a useful package library that enables developers to work with input and output streams in Ruby more efficiently while coding in C#.