module ApplicationHelper
ApplicationController.class_eval do
layout "standard-layout"
end
end
This makes all ApplicationControllers use the layout "standard-layout", defined from a central location. The source of this string could be anything from a cookie to preferences stored on a model object, and obviously one would probably not apply it to ApplicationController indiscriminately; but the concept is fun :)
Anoter example would be for a routeless static content controller:
class StaticController < ApplicationController
def method_missing(action)
render :action => action.to_s
end
end
This basically emulates having a method defined for any that is called and renders a template of same name using the rhtml file in the views directory. Again, maybe not the best way to have static content, but it's a fun idea.
That is one thing that scares me about metaprogramming--without discipline and a concept of what's best vs. what's cool, an app can become hell very quickly.