shiika icon indicating copy to clipboard operation
shiika copied to clipboard

Create #inspect on defining a class

Open yhara opened this issue 4 years ago • 1 comments

class A; def initialize(@a: Int, @b: String); end; end
p A.new(123, "foo")

Currently this prints #<?>. It is nice if it prints #<A @a=123, @b="foo">

yhara avatar Jan 13 '21 15:01 yhara

It seems hard to implement this in Rust. Ideally it should be implemented in Shiika like this

class Object
  def inspect -> String
    ivar_desc = self.instance_variables.map{|name, value|
      "#{name}: \{value}"
    }.join(" ")
    "#<#{self.class.name} #{ivar_desc}>"
  end
end

yhara avatar Jan 19 '21 02:01 yhara