On Mar 6, 2:24 pm, "Pedro Del Gallego" <pedro.delgall... / gmail.com>
wrote:
> but i ve a proble when i try to move the pre and post method to a
> module. Can anyone explainme why the pre methods is  undefined in the
> class ?
[snip]

Including a Module into a Class only links in the 'instance' methods
of that module as instance methods of the class. Module methods (def
self.foo) are not inherited as 'class' methods.

See http://phrogz.net/RubyLibs/RubyMethodLookupFlow.png for a visual
explanation.

The easiest thing to do is make those methods instance methods of the
module, and extend your Song class with them:

module Foo
  def bar; puts "#bar called on #{self}"; end
end

class Cat
  include Foo
end

class Dog
  extend Foo
end

Cat.bar      rescue puts "No Cat.bar method!"
Cat.new.bar  rescue puts "No Cat#bar method!"
Dog.bar      rescue puts "No Dog.bar method!"
Dog.new.bar  rescue puts "No Dog#bar method!"

#=> No Cat.bar method!
#=> #bar called on #<Cat:0x28347b0>
#=> #bar called on Dog
#=> No Dog#bar method!