What you means is this?
def superclasses : Array(Crystal::Meta::AbstractType)
a = [] of Crystal::Meta::AbstractType
{% begin %}
{% superklass = @type.superclass %}
until {{ superklass }} == Object
a << Crystal::Meta::Type.new({{superklass.name(generic_args: false)}})
{% superklass = superklass.superclass %}
end
{% end %}
a << Crystal::Meta::Type.new(Object)
end
although this code not work because dead loop.
BUG: {{ @type.name.stringify }} (Crystal::MacroExpression) at /home/zw963/Crystal/share/crystal/src/class.cr:149:11 should have been expanded (Exception)
I thought i don’t really understand why wrap those class into a Crystal::Meta::Type
or Crystal::Meta::AbstractType
is necessary, this may take some time to learn, but anyway, i add a Object#all_methods, it works as my expected.
def all_methods : Hash(String, Array(Crystal::Meta::AbstractMethod))
a = {self.class.to_s => methods}
superklass = self.superclass
until superklass == Object
a[superklass.to_s] = superklass.methods
superklass = superklass.superclass
end
a["Object"] = Object.methods
a
end
file.all_methods # => {"File" =>
[def initialize(path : ::String, fd, blocking, encoding, invalid),
def path() : String,
def size() : Int64,
def truncate(size = 0) : Nil,
def read_at(offset, bytesize),
def inspect(io : IO) : Nil,
def chown(uid : Int = -1, gid : Int = -1) : Nil,
def chmod(permissions : Int | Permissions) : Nil,
def utime(atime : Time, mtime : Time) : Nil,
def touch(time : Time = Time.utc) : Nil,
def delete() : Nil],
"IO::FileDescriptor" =>
[def noecho(),
def noecho!(),
def cooked(),
def cooked!() : Nil,
def raw(),
def raw!(),
def preserving_tc_mode(msg),
def fd() : Int,
def initialize(fd, blocking),
def blocking(),
def blocking=(value),
def close_on_exec?() : Bool,
def close_on_exec=(value : Bool),
def fcntl(cmd, arg = 0),
def info(),
def seek(offset, whence : Seek = Seek::Set),
def seek(offset, whence : Seek = Seek::Set),
def unbuffered_pos() : Int64,
def pos=(value),
def fsync(flush_metadata = true) : Nil,
def flock_shared(blocking = true),
def flock_shared(blocking = true) : Nil,
def flock_exclusive(blocking = true),
def flock_exclusive(blocking = true) : Nil,
def flock_unlock() : Nil,
def finalize(),
def closed?() : Bool,
def tty?() : Bool,
def reopen(other : IO::FileDescriptor),
def inspect(io : IO) : Nil,
def pretty_print(pp),
def unbuffered_rewind(),
def unbuffered_close(),
def unbuffered_flush()],
"IO" =>
[def read(slice : Bytes),
def write(slice : Bytes) : Nil,
def close(),
def closed?() : Bool,
def check_open(),
def flush(),
def <<(obj) : self,
def print(obj : _) : Nil,
def print(*) : Nil,
def puts(string : String) : Nil,
def puts(obj : _) : Nil,
def puts() : Nil,
def puts(*) : Nil,
def printf(format_string, args : Array | Tuple) : Nil,
def printf(format_string, *) : Nil,
def read_byte() : UInt8 | ::Nil,
def read_char() : Char | ::Nil,
def read_char_with_bytesize(peek),
def peek_or_read_utf8(peek, index),
def peek_or_read_utf8_masked(peek, index),
def read_utf8_byte() : UInt8 | ::Nil,
def read_utf8(slice : Bytes),
def read_string(bytesize : Int) : String,
def peek() : Bytes | ::Nil,
def write_string(slice : Bytes) : Nil,
def write_utf8(slice : Bytes) : Nil,
def encoder(),
def decoder(),
def read_fully(slice : Bytes) : Int32,
def read_fully?(slice : Bytes) : Int32 | ::Nil,
def gets_to_end() : String,
def getb_to_end() : Bytes,
def gets(limit : Int, chomp) : String | ::Nil,
def gets(delimiter : Char, limit : Int, chomp) : String | ::Nil,
def gets(delimiter : Char, chomp) : String | ::Nil,
def gets(delimiter : String, chomp) : String | ::Nil,
def gets(chomp = true) : String | ::Nil,
def gets_peek(delimiter, limit, chomp, peek),
def gets_slow(delimiter : Char, limit, chomp),
def read_line(*) : String,
def skip(bytes_count : Int) : Nil,
def skip_to_end() : Nil,
def write_byte(byte : UInt8) : Nil,
def write_bytes(object, format : IO::ByteFormat = IO::ByteFormat::SystemEndian) : Nil,
def read_bytes(type, format : IO::ByteFormat = IO::ByteFormat::SystemEndian),
def tty?() : Bool,
def each_line(*) : Nil,
def each_line(*),
def each_char() : Nil,
def each_char(),
def each_byte() : Nil,
def each_byte(),
def rewind(),
def set_encoding(encoding : String, invalid : Symbol | ::Nil) : Nil,
def encoding() : String,
def utf8_encoding?(encoding : String, invalid : Symbol | ::Nil) : Bool,
def has_non_utf8_encoding?() : Bool,
def seek(offset, whence : Seek = Seek::Set),
def pos(),
def pos=(value),
def tell(),
def read_at(offset, bytesize)],
"Reference" =>
[def object_id() : UInt64,
def ==(other : self),
def ==(other : JSON::Any),
def ==(other),
def same?(other : Reference) : Bool,
def same?(other : Nil),
def dup(),
def hash(hasher),
def inspect(io : IO) : Nil,
def pretty_print(pp) : Nil,
def to_s(io : IO) : Nil,
def exec_recursive(method),
def exec_recursive_clone(),
def initialize()],
"Object" =>
[def ==(other),
def !=(other),
def !~(other),
def ===(other : JSON::Any),
def ===(other),
def =~(other),
def hash(hasher),
def hash(),
def to_s(io : IO) : Nil,
def to_s() : String,
def inspect(io : IO) : Nil,
def inspect() : String,
def pretty_print(pp : PrettyPrint) : Nil,
def pretty_inspect(width = 79, newline = "\n", indent = 0) : String,
def tap(),
def try(),
def in?(collection : Object) : Bool,
def in?(*) : Bool,
def not_nil!(),
def itself(),
def dup(),
def unsafe_as(type : T.class),
def class(),
def crystal_type_id() : Int32,
def methods(),
def all_methods() : Hash(String, Array(Crystal::Meta::AbstractMethod)),
def instance_vars() : Array(String),
def superclass() : Class,
def superclasses() : Array(String),
def to_json(io : IO) : Nil,
def to_json() : String,
def to_pretty_json(indent : String = " ") : String,
def to_pretty_json(io : IO, indent : String = " ") : Nil]}