Search code examples
ruby-on-railsruby-on-rails-2

Rails call back before every calling a method before every static method


I need to call a method before every static method called in rails.

is it possible

Example:

Class A

 #Here a bunch of statements before every static method

 def self.b
  # some code related to b
 end

  def self.a
  # some code related to a
 end
end

when I call A.b then the output should be:

==========

bunch of statements before every static method and

code related to b

==========

Thanks in advance


Solution

  • Try this

    class A
    
     def self.hello
       print "how are"
    
     end
    
     def self.before_stuff
      print "you"
     end
    
     begin
      print "hello,"
     end
    end
    
     A.hello