I was reading the Rails docs, and I have encountered the term macros
.
I can't find the definition of the term (in the context of Rails).
Can someone point me to a place where the term is defined?
I am familiar with the term in a different context as a software for "recording" actions (mouse, keyboard actions in OS, for instance). Is there any connection between the different uses of the term?
In this context, a macro is a piece of code that generates some other code. For example:
attr_accessor :foo
generates this:
def foo
@foo
end
def foo=(val)
@foo = val
end
Is there any connection between the different uses of the term?
Kind of. You could say that author of attr_accessor
"recorded" what it should expand to.
In Ruby a macro is like a method, just some code, that instead of returning a Ruby datatype returns more Ruby code! This code will get executed along with all the other code you have written when you run your program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With