pub fn eval(
ruby_code: &str,
binding: Binding,
filename_for_debugging: Option<&str>,
) -> Result<Value, CaughtException>Expand description
Evaluate Ruby code in a specific binding.
Rescues all Ruby exceptions.
Examples found in repository?
examples/repl.rs (line 16)
3fn main() {
4 unsafe { mri_sys::ruby_init() };
5
6 loop {
7 print!("cool-interpreter:8=====D -- ");
8 std::io::stdout().flush().unwrap();
9
10 let mut input = String::new();
11 std::io::stdin().read_line(&mut input).expect("could not read from stdin");
12
13 match &input.trim().to_lowercase()[..] {
14 "exit" | "quit" => break,
15 "help" => println!("-> https://www.eapservices.co.nz/"),
16 _ => match mri_sys::helpers::eval(&input, mri_sys::helpers::Binding::top_level(), Some("mock-filename.rb")) {
17 Ok(value) => println!("-> {:?}", value),
18 Err(e) => eprintln!("ERROR, EXCEPTION RAISED: {}", e),
19 },
20 }
21 }
22
23 unsafe { mri_sys::ruby_cleanup(0) };
24}