From 78a5457f819380a00426711381c37330f03197bb Mon Sep 17 00:00:00 2001 From: Aotokitsuruya Date: Thu, 12 Sep 2024 20:40:01 +0800 Subject: [PATCH] Implement minimal #inspect method support --- features/object.feature | 7 +++++++ kernel.go | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/features/object.feature b/features/object.feature index 6df4758..59e8996 100644 --- a/features/object.feature +++ b/features/object.feature @@ -17,3 +17,10 @@ Feature: Object Hello.new.world """ Then there should return string "world" + + Scenario: I can new a object + When I execute ruby code: + """ + Object.inspect + """ + Then there should return string "Object" diff --git a/kernel.go b/kernel.go index 3d4a9b8..5830404 100644 --- a/kernel.go +++ b/kernel.go @@ -1,7 +1,17 @@ package mruby func objectInspect(mrb *State, self Value) Value { - return nil + switch v := self.(type) { + case *Object: + return "Object" + case *Class: + name := mrb.ObjectInstanceVariableGet(v, _classname(mrb)) + return name + case *Module: + return "Module" + default: + return nil + } } func initKernel(mrb *State) (err error) {