Skip to content

Instantly share code, notes, and snippets.

@dtrasbo
Created December 5, 2010 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dtrasbo/729150 to your computer and use it in GitHub Desktop.
Save dtrasbo/729150 to your computer and use it in GitHub Desktop.
class TheUppermostClass
def initialize(one, two, three, four)
end
end
class TheInheritingClass < TheUppermostClass
def initialize(one, two, three)
super(one, two, three, 'four')
end
end
class TheInheritingClass
def initialize(*args)
super
# You would expect this to call TheInheritingClass#initialize because that's
# the method we're overriding.
end
end
TheInheritingClass.new('one', 'two', 'three')
# But the above results in an argument error (3 for 4) because it actually calls
# the superclass, TheUppermostClass.
# How to fix?
@jeffkreeftmeijer
Copy link

super won't call the method your overriding, you'll have to do something like this: https://gist.github.com/729165 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment