News for hackers. Stuff that matters.
Re:Why don't I metaprogram more? by stevepike on Thursday August 14, 2014 @09:36PM (#8180664)
The CanCan ruby authorization library does a neat bit of metaprogramming. It offers a function "load_resource" which you put at the top of your controller. The function uses the name of the controller class and the name of the currently executing controller action to automatically set a resource. It looks like this:

   class CarsController < ActionController::Base
     load_resource
   
     def index
       # @cars is defined
     end

     def show
       # @car is defined
     end
   end

There are no comments on this comment yet.