rails/rails — pull request #7613 by marcandre (2012-09-12 04:33:09+00:00)
Title: Nice and easy delegation to the class

Simple patch to allow delegation to class. With it, one can:

class FooFeatureController < ActionController::Base
def self.feature_name
controller_name.sub /_feature$/, ''
end
# In the same way that controller_name is available from the instances too:
delegate :feature_name, :to => :class
end

Without it, one gets a relatively obscure syntax error message.

rails/activesupport/lib/active_support/core_ext/module/delegation.rb:142:in `module_eval': test/core_ext/module_test.rb:37: syntax error, unexpected '.' (SyntaxError)
class.table_name(*args, &block) ...
^
test/core_ext/module_test.rb:39: syntax error, unexpected '.'
if class.nil? ...
^
test/core_ext/module_test.rb:44: syntax error, unexpected keyword_end, expecting $end
end # end
^

It's already possible to use `delegate :foo, :to => 'self.class'` but that is less obvious (and also won't give the expected result with `:prefix => true`)