Skip to content

Commit

Permalink
! in an included module calling super is more appropriate than
Browse files Browse the repository at this point in the history
alias_method_chaining
  • Loading branch information
Niko Dittmann committed Mar 2, 2010
1 parent ef59ac6 commit 761c6af
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions lib/sinatra/resources.rb
@@ -1,21 +1,9 @@
module Sinatra
module Resources
def self.registered(app)
[:get, :post, :put, :delete].each do |meth|
# http://whynotwiki.com/Ruby_/_Method_aliasing_and_chaining#Can_you_alias_class_methods.3F
app.class_eval <<-EndAlias
class << self
alias_method :#{meth}_without_resource, :#{meth}
alias_method :#{meth}, :#{meth}_with_resource
end
EndAlias
end
end

[:get, :post, :put, :delete].each do |meth|
class_eval <<-EndMeth
def #{meth}_with_resource(path=nil, options={}, &block)
#{meth}_without_resource(make_path(path), options, &block)
def #{meth}(path=nil, options={}, &block)
super(make_path(path), options, &block)
end
EndMeth
end
Expand Down

0 comments on commit 761c6af

Please sign in to comment.