Skip to content

Instantly share code, notes, and snippets.

@duairc
Created August 6, 2009 01:55
Show Gist options
  • Save duairc/163085 to your computer and use it in GitHub Desktop.
Save duairc/163085 to your computer and use it in GitHub Desktop.
class Window < Gtk::Window
include Helper
def initialize
# @stocks, @icons, etc will already be defined at this point
end
end
window = Window.new
# Window's "new" class method was overridden by Helper
# The over-ridden new method then checks to see if the class has an instance method called __initialize
# If it doesn't, it aliases the old initialize method to __initialize and replaces it with something that creates @stocks, etc before calling __initialize
# The reason I couldn't just override the initialize method in the first place and had to do it through the classes new method was because initialize may not have been defined at the point that Helper is included in something
# When initialize does get defined it would just override the one that Helper defined which would ruin the whole thing (not to mention that alias_method :__initialize, :initialize wouldn't really make sense because :initialize isn't defined)
# I figure it's probably safe to assume that initialize has been defined by the time somebody tries to instanciate the class, i.e., when Class.new is called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment