# Rails adds send! method to Object?

**URL:** <https://www.ruby-forum.com/t/rails-adds-send-method-to-object/172255>\
**Category:** Rails\
**Created:** [July 17, 2009, 5:48pm UTC](https://www.ruby-forum.com/t/rails-adds-send-method-to-object/172255 "2009-07-17T17:48:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 17, 2009, 5:48pm UTC](https://www.ruby-forum.com/t/rails-adds-send-method-to-object/172255/1 "2009-07-17T17:48:50Z")

</div>

All,

It appears that Rails adds the send! method to Object, via the output  
below.

gandalf-2:royaltyzone weyus$ irb

> > Object.methods.include?(“send!”)  
> > =\> false
> 
> > exit  
> > gandalf-2:royaltyzone weyus$ script/console  
> > Loading development environment (Rails 2.1.2)
> 
> > Object.methods.include?(“send!”)  
> > =\> true
> 
> > exit

I assume this is to provide backward compatibility with the new send!  
method in Ruby 1.9 that allows you to still dynamically call private  
methods? Is this correct?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 17, 2009, 6:44pm UTC](https://www.ruby-forum.com/t/rails-adds-send-method-to-object/172255/2 "2009-07-17T18:44:07Z")

</div>

Hi –

On Fri, 17 Jul 2009, Wes G. wrote:

> gandalf-2:royaltyzone weyus$ script/console  
> Loading development environment (Rails 2.1.2)
> 
> > > Object.methods.include?(“send!”)  
> > > =\> true  
> > > exit
> 
> I assume this is to provide backward compatibility with the new send!  
> method in Ruby 1.9 that allows you to still dynamically call private  
> methods? Is this correct?

There’s no send! in 1.9. I wish there were; I like send/send! more  
than public\_send/send, and I think Matz put it in there briefly but  
then decided that switching the sense of send was too  
backwards-incompatible. Also there was some question which was the  
“dangerous” one: the one that included private methods, or the one  
that didn’t.

It appears to be gone from Rails, so maybe it was only there during  
the brief period that it was in 1.9.

$ ./script/console  
Loading development environment (Rails 2.3.2)

> > Object.new.send!  
> > NoMethodError: undefined method `send!’ for #Object:0x2378780  
> > from (irb):6

David

–  
David A. Black / Ruby Power and Light, LLC  
Ruby/Rails consulting & training: [http://www.rubypal.com](http://www.rubypal.com)  
Now available: The Well-Grounded Rubyist ([The Well-Grounded Rubyist](http://manning.com/black2))  
Training! Intro to Ruby, with Black & Kastner, September 14-17  
(More info: [http://rubyurl.com/vmzN](http://rubyurl.com/vmzN))

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 17, 2009, 7:11pm UTC](https://www.ruby-forum.com/t/rails-adds-send-method-to-object/172255/3 "2009-07-17T19:11:17Z")

</div>

I’m using Rails 2.1.2 at the moment.

So I need to reliably call a private method dynamically, and I don’t  
want to have to change how I do it when I move to Rails 2.3.2 nor Ruby  
1.9.

Should I use Object#send or something else?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 17, 2009, 7:19pm UTC](https://www.ruby-forum.com/t/rails-adds-send-method-to-object/172255/4 "2009-07-17T19:19:46Z")

</div>

Hi –

On Fri, 17 Jul 2009, Wes G. wrote:

> I’m using Rails 2.1.2 at the moment.
> 
> So I need to reliably call a private method dynamically, and I don’t  
> want to have to change how I do it when I move to Rails 2.3.2 nor Ruby  
> 1.9.
> 
> Should I use Object#send or something else?

Object#send (or **send** , if you like that one) should be fine. It  
looks like Rails’s send! is just an alias. From ActiveSupport:

class Object  
unless respond\_to?(:send!)  
# Anticipating Ruby 1.9 neutering send  
alias send! send  
end

“Neutered” meaning that it won’t call private methods, I assume – but  
that decision was rescinded.

David

–  
David A. Black / Ruby Power and Light, LLC  
Ruby/Rails consulting & training: [http://www.rubypal.com](http://www.rubypal.com)  
Now available: The Well-Grounded Rubyist ([The Well-Grounded Rubyist](http://manning.com/black2))  
Training! Intro to Ruby, with Black & Kastner, September 14-17  
(More info: [http://rubyurl.com/vmzN](http://rubyurl.com/vmzN))
