0

I saw this question (Executing code for every method call in a Ruby module) and was interested to see what kinds of other things are built into Ruby.

Some simple searches didn't bring up anything beyond stackoverflow questions, so I'm wondering where this information can be found.

Community
  • 1
  • 1
MxLDevs
  • 19,048
  • 36
  • 123
  • 194
  • Take a look at the Module and Object documentation. They have a lot of the metaprogramming methods. – Linuxios Nov 06 '13 at 16:45
  • `before` is not a built-in method, it's [metaprogramming](http://ruby-metaprogramming.rubylearning.com). – AShelly Nov 06 '13 at 16:46
  • Oops, yes now that I look at what's going on, it's just re-defining the method by adding some stuff before calling the original method. – MxLDevs Nov 06 '13 at 16:49

2 Answers2

1

The before method from you linked question is not built into Ruby. Instead, it is a custom built "extension" (in fact, an ordinary module, depending on the actual implementation) that gets included and manipulates some methods, typically be defining a new one with the same name as the old one which does something and then calls the old one.

While this kind of meta-programming is rather easy with ruby, the specific functionality is not a actually Ruby feature. Instead, it is a partial implementation of Aspect Oriented Programming that is possible due to Ruby's meta-programming capabilities.

Holger Just
  • 52,918
  • 14
  • 115
  • 123
0

The before method in the question you linked to is not part of Ruby. It is a user-defined method.

Patrick Oscity
  • 53,604
  • 17
  • 144
  • 168