Ruby - Advanced Metaprogramming
Given this Ruby code using a hook pattern:
What is the output when
class Framework
def self.before_save(&block)
@before_save_hook = block
end
def save
self.class.instance_variable_get(:@before_save_hook)&.call
puts 'Saving data'
end
end
class User < Framework
before_save { puts 'Validate user' }
end
User.new.saveWhat is the output when
User.new.save is called?