Skip to content

Instantly share code, notes, and snippets.

@jbrechtel
Created July 1, 2012 16:24
Show Gist options
  • Select an option

  • Save jbrechtel/3028855 to your computer and use it in GitHub Desktop.

Select an option

Save jbrechtel/3028855 to your computer and use it in GitHub Desktop.
overriding new
class Parent
class << self
alias_method :orig_new, :new
def new(arg)
puts "newing parent with #{arg}"
orig_new
end
end
def parent_method
puts 'and inherits..'
end
end
class YourChild < Parent
def self.new
super("child args")
end
def child_method
puts 'see? really the child'
end
end
puts YourChild.new.child_method
puts YourChild.new.parent_method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment