In Ruby, it is very helpful to use introspection methods(like #constants
) to discover new APIs.
By analogy, I tried the same in Crystal, with this example:
require "gobject/gtk/autorun"
window = Gtk::ApplicationWindow.new(title: "AccelGroup", border_width: 20)
window.connect "destroy", ->Gtk.main_quit
window.add Gtk::Label.new("Press Ctrl+S")
accel_group = Gtk::AccelGroup.new
accel_group.connect(Gdk::KEY_S, :control_mask, :zero_none) do
puts "Ctrl+S pressed!"
end
window.add_accel_group(accel_group)
p! Gdk.constants
window.show_all
But it failed to compile with:
| p! Gdk.constants
^--------
Error: undefined method 'constants' for Gdk:Module
I intended to find out what other combinations besides Ctrl+S(Gdk::KEY_S
) are there.
I wonder, in similar situations, what do you use for introspection in Crystal?