Skip to content

Commit

Permalink
Make #inspect method can return class, module and object classname
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Sep 19, 2024
1 parent 9f0b734 commit 748b75e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions features/class.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ Feature: Class
"""
class Foo
end
Foo
Foo.inspect
"""
Then there should return class "Foo"
Then there should return string "Foo"
7 changes: 7 additions & 0 deletions features/kernel.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Kernel
Scenario: I can inspect Kernel module to get its name
When I execute ruby code:
"""
Kernel.inspect
"""
Then there should return string "Kernel"
11 changes: 8 additions & 3 deletions features/object.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ Feature: Object
"""
Then there should return string "world"

Scenario: I can inspect Object to get its name
Scenario: I can inspect object which is an instance of a class
When I execute ruby code:
"""
Object.inspect
class Hello
def world
"world"
end
end
Hello.new.inspect
"""
Then there should return string "Object"
Then there should return string "Hello"
7 changes: 3 additions & 4 deletions kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import "fmt"
func objectInspect(mrb *State, self Value) Value {
switch v := self.(type) {
case *Object:
return "Object"
case *Class:
name := mrb.ObjectInstanceVariableGet(v.Class(), _classname(mrb))
return name
case RClass:
name := mrb.ObjectInstanceVariableGet(v, _classname(mrb))
return name
case *Module:
return "Module"
default:
return nil
}
Expand Down

0 comments on commit 748b75e

Please sign in to comment.