<commit_before><?php

namespace App\Virtualizor\Lang;

use System\Contracts\App\Virtualizor\LangContract;

/**
 * @author <NAME> <<EMAIL>>
 * @license MIT
 */
class Ruby implements LangContract
{
}<commit_msg>Improve Ruby virtualizor<commit_after><?php

namespace App\Virtualizor\Lang;

use System\Contracts\App\Virtualizor\LangContract;

/**
 * @author <NAME> <<EMAIL>>
 * @license MIT
 */
class Ruby implements LangContract
{
	/**
	 * @var string
	 */
	private $rubyCode;

	/**
	 * @var string
	 */
	private $hash;

	/**
	 * @var string
	 */
	private $file;

	/**
	 * Constructor.
	 *
	 * @param string $rubyCode
	 */
	public function __construct($rubyCode)
	{
		$this->rubyCode = $rubyCode;
		$this->hash		= sha1($rubyCode);
		$this->file     = VIRTUALIZOR_DIR."/ruby/".$this->hash.".rb";
	}

	private function __init()
	{
		if (! is_dir(VIRTUALIZOR_DIR."/ruby")) {
			$exe = shell_exec("mkdir -p ".VIRTUALIZOR_DIR."/ruby");
			if (! is_dir(VIRTUALIZOR_DIR."/ruby")) {
				throw new \Exception($exe, 1);
			}
		}

		if (! file_exists($this->file)) {
			$handle = fopen($this->file, "w");
			fwrite($handle, $this->rubyCode);
			fclose($handle);
		}
	}

	public function exec()
	{
		$this->__init();
		$sh = shell_exec("ruby ".$this->file." 2>&1");
		return $sh == "" ? "~" : $sh;
	}
}
{'fraction_non_alphanumeric': 0.19502719502719504, 'fraction_numerical': 0.003108003108003108, 'mean_word_length': 3.410958904109589, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2343447', 'n_tokens_mistral': 545, 'n_tokens_neox': 481, 'n_words': 89}