Understanding Ruby on Rails send (: include

I am trying to develop a Redmine Plugin, I started reading the documentation , as well as a lot of learning Ruby and a lot of Ruby on Rails. (I'm a PHP / Python / js guy)

Then I started looking at other plugins and I found this code . I cannot find enough information to fully understand how this line of code works:

Issue.send(:include, RedmineRequireIssueAllowedToChangeAssignee::Patches::IssuePatch) 

I understand that there are some things inside IssuePatch to override or add an Issue class.

Then I found this , explaining the use of dispatch, and it bothers me, why not use only Issue.include?

The main question is: where is this include method defined and what does it do?

UPDATE: related question

+4
source share
1 answer

You can't just do include because it is a private method, so you use send , which bypasses ruby ​​visibility control. With send you can call any method, even a private one (as in this case).

where does this method include specific and what does it do?

It is defined as Module # include and when called with a module as a parameter, it attaches all the instance methods of this module to the receiver (which is in your case, the Issue class). This is a very common idiom in Ruby.

+7
source

Source: https://habr.com/ru/post/1447990/


All Articles