Created
August 11, 2010 10:09
-
-
Save simon-engledew/518775 to your computer and use it in GitHub Desktop.
ruby lambda in a different scope
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 ApplicationController < ActionController::Base | |
def self.before_filter_in_instance(&block) | |
before_filter do |controller| | |
controller.instance_eval(&block) | |
end | |
end | |
# fails! | |
# params is not available | |
# this lambda will be executed in the class scope where it was defined | |
before_filter lambda { Rails.logger.info(params[:transaction_id]) } | |
# succeeds! | |
# params is available | |
# this lambda will be executed inside the instance of controller | |
before_filter_in_instance { Rails.logger.info(params[:transaction_id]) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment