Skip to content

Instantly share code, notes, and snippets.

@cannikin
Last active February 16, 2018 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cannikin/8c39fba6bea9e5884f7e51739f69bf37 to your computer and use it in GitHub Desktop.
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
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