Last active
February 16, 2018 19:10
-
-
Save cannikin/8c39fba6bea9e5884f7e51739f69bf37 to your computer and use it in GitHub Desktop.
Two different forms of `include` in Ruby, only one of which works as expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BustedInclude | |
include ActiveModel::Validations, ActiveModel::Validations::Callbacks | |
before_validation { puts 'Callback!' } | |
end | |
# outputs only `true` | |
instance = BustedInclude.new | |
instance.valid? | |
class WorkingInclude | |
include ActiveModel::Validations | |
include ActiveModel::Validations::Callbacks | |
before_validation { puts 'Callback!' } | |
end | |
# outputs "Callback!" and then `true` | |
instance = WorkingInclude.new | |
instance.valid? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment