@RubyLevelMethod(name = "open") public static RubyValue open(RubyValue receiver, RubyArray args, RubyBlock block) { String filename = args.get(0).toStr(); RubyIO io; if (args.size() <= 1) { io = ObjectFactory.createFile(filename, "r"); } else if (args.get(1) instanceof RubyFixnum) { String mode = "r"; int i = args.get(1).toInt(); if ((i & RDWR) != 0) { mode = mode + "w"; } io = ObjectFactory.createFile(filename, mode); } else { RubyString mode = (RubyString) args.get(1); io = ObjectFactory.createFile(filename, mode.toString()); } if (null == block) { return io; } else { RubyValue v = block.invoke(receiver, io); io.close(); return v; } }