I'm trying to develop a Redmine Plugin, I started reading the documentation , and learning a lot of Ruby and a lot of Ruby on Rails. (I'm a PHP/Python/js guy)
Then I started looking through other plugins, and I found this code . I can't find enough information to fully understand how this line of code works:
Issue.send(:include, RedmineRequireIssueAllowedToChangeAssignee::Patches::IssuePatch)
I understand that inside IssuePatch are some things to override or add to Issue class.
Then I found this , explaining the use of send, and that confuses me, why not use just Issue.include?
The main question would be: where is this method include
defined and what does it does?
UPDATE: related question
You can't just do include
because it's a private method, so you use send
which circumvents ruby visibility control. With send
you can call any method, even private ones (as in this case).
where is this method include defined and what does it does?
It's defined as Module#include and, when invoked with a module as a parameter, it appends all instance methods of that module to the receiver (which is, in your case, Issue
class). It's a very-very common idiom in Ruby.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.