Skip to content

Instantly share code, notes, and snippets.

@sxross
Created February 5, 2013 03:07
Show Gist options
  • Save sxross/4711848 to your computer and use it in GitHub Desktop.
Save sxross/4711848 to your computer and use it in GitHub Desktop.
Super in module context
module MotionModel
module Model
def save(*)
puts "called MM#save"
end
end
end
module MotionModel
module Paranoid
def save(paranoid = false)
puts paranoid ? "called Paranoid save" : super
end
end
end
class MyModel
include MotionModel
include Paranoid
end
model = MyModel.new
model.save
model.save(true)
@ivanacostarubio
Copy link

Hey!

I run that code and I get http://pastie.org/private/zud0x6kz73ckytlnwng8q

however, I am running it on 1.9.3.

@ivanacostarubio
Copy link

This reassembles more closely to what we have in MotionModel::Paranoid: https://gist.github.com/ivanacostarubio/4711920

The first: model.save fail because of validations. The second model.save(true) valls the save method in MotionModel::Model because it passed the validations.

Maybe there is something that I am not seing. Thank you for helping me understand it. :)

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