5

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

Community
  • 1
  • 1
jperelli
  • 6,988
  • 5
  • 50
  • 85

1 Answers1

8

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.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367