On Wed, Aug 12, 2009 at 5:50 PM, Cris Shupp<cshupp1 / yahoo.com> wrote:
> Gurus,
>
> I am reading the O'Reilly book "Rails: Up and Running, 2nd Edition" and
> the author told me to add the following line of code:
>
> skip_before_filter :verify_authenticity_token
>
> as follows:
>
> class SlidesController < ApplicationController
> skip_before_filter :verify_authenticity_token
> ...
>
> This stopped me dead in my tracks as I realized I had no idea what was
> going on. I am using Aptana (Eclipse) and so it can tell me that
> skip_before_filter is defined in the module ClassMethods. I am assuming
> that somehow this method (skip_before_filter) is mixed in?
>
> The implementation is:
>   def skip_before_filter(*filters)
>    filter_chain.skip_filter_in_chain(*filters, &:before?)
>   end
>
> What is *filters? Did I miss this in my 'Learning Ruby' book?
>
This collects all of the arguments into an array called filters.  You
can find more looking for "ruby splat" on google.

> Anyway, I guessed that I was calling the method 'skip_before_filter'
> sometime during my controller's construction. So I built a toy to
> validate as follows:
> ####################BEGIN
> test.rb###############################################
> module Test
> def call_me
>  puts "Mixin called"
> end
> end
> module Test2
> def call_me
>  puts "second mixin called"
> end
> end
>
> class Tester
> include Test, Test2
> #call_me() #this call fails. This blows my theory...
>
> def initialize
>  super
>  call_me()# this call works, but how would I call the other one?
>  #Test2::call_me()#this call fails
>  puts "A tester was built"
> end
>
> end
>
> Tester.new
> ########################################END test.rb###########
>
> output is:
> Mixin called
> A tester was built
>

Rails uses a convention with modules similar to the following:

module FooBehaviors
  def self.included(base)
    base.extend(ClassMethods)
  end
  module ClassMethods
    def foo
      puts 42
    end
  end
end

class Bar
  include FooBehaviors
  foo
end

When FooBehaviors module is included, it also extends the including
class with the FooBehaviors::ClassMethods module.  You can find out
more by looking at the differences between include and extend.

http://railstips.org/2009/5/15/include-verse-extend-in-ruby

Best,
Michael Guterl