From: Jim Morris Date: 2005-06-20T06:17:46+09:00 Subject: Ruby/DL struct inspection? Hi Ruby/DL experts... I want to print out the values of the members of a DL struct, is there a way for the actual instance of the struct to know this? An example of how I currently do it is below in printStruct, however this requires that I have both the instance and the Class name of the struct, then I use the Struct::members method of the class. However it would be nice if I could get this all from the instance s which appears to be type DL::Importable::Internal::Memory and seems to have no reference to Svn_status_t which is DL::Importable::Internal::Struct require 'dl/import' require 'dl/struct' module Svnrb extend DL::Importable Svn_status_t = struct [ "void *entry", "int text_status", "int prop_status", "int locked", "int copied", "int switched", "int repos_text_status", "int repos_prop_status", "void *repos_lock" ] # I want to print the value of each member of s, but I also need to know the class # which is hard coded here and shouldn't be def printStruct(s) Svn_status_t.members.each do |name| print " ", name, ": " , eval("s.#{name}"), "\n" end end # pstatus comes from a c routine and is a pointer to a c struct status= Svn_status_t.new(pstatus) p status printStruct(status) end