Skip to content

Instantly share code, notes, and snippets.

@duairc
Created August 6, 2009 00:25
Show Gist options
  • Save duairc/163061 to your computer and use it in GitHub Desktop.
Save duairc/163061 to your computer and use it in GitHub Desktop.
module Helper
# ...
class << self
def included(base)
base.class_eval do
(class << self; self; end).class_eval do
alias_method :__new, :new
private :__new
define_method(:new) do |*args|
base.class_eval do
unless instance_methods.include? :__initialize
alias_method :__initialize, :initialize
private :__initialize
def initialize(*args)
@icons = Gtk::IconFactory.new
@icons.add_default
@stocks = {}
Gtk::Stock.constants.each do |c|
begin
s = c.to_sym
id = Gtk::Stock.const_get(s)
@stocks[s], = Gtk::Stock.lookup(id)
rescue ArgumentError then end
end
@actions = Hash.new do |hash, key|
value = Gtk::ActionGroup.new(key.to_s)
hash[key] = value
value.instance_eval do
class << self
def add(*actions)
actions.each do |action|
add_action(action)
end
end
end
end
value
end
@accels = Gtk::AccelGroup.new
__initialize(*args)
add_accel_group(@accels)
end
end
end
__new(*args)
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment