Forum: Ruby on Rails What does ActiveRecord#send do?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8217faf2bfdfa7daf10135d41ddd421e?d=identicon&s=25 Jeff Cohen (jeff)
on 2005-11-24 03:10
Apologies in advance for the newbie question...

I've seen usage of a "send" method on ActiveRecord objects but I'm not
sure what it's intending to do.  For example, scaffolding will use the
.send method on the model object in the list template.

I checked api.rubyonrails.com page but somehow didn't find any specifics
about it.

Can someone explain what it's used for?

Thanks!
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 technoweenie (Guest)
on 2005-11-24 03:15
(Received via mailing list)
On 11/23/05, Jeff Cohen <cohen.jeff@gmail.com> wrote:
>
> Thanks!

#send is inherited from Object:

http://ruby-doc.org/core/classes/Object.html#M000998

These statements are equal:

@person.age
@person.send :age

@person.age = 5
@person.send :age=, 5

@person.set_age(5)
@person.send :set_age, 5


--
rick
http://techno-weenie.net
8217faf2bfdfa7daf10135d41ddd421e?d=identicon&s=25 Jeff Cohen (jeff)
on 2005-11-24 03:17
technoweenie wrote:
> These statements are equal:
>
> @person.age
> @person.send :age
>

Ah!  So it's a way to dynamically call a method given its name - very
cool.

Thanks again.
Fcc360652e5fa2ece36b68dafe4af7e8?d=identicon&s=25 Wwwfernand Wwwfernand (wwwfernand)
on 2017-02-22 15:15
i'm sorry and thank you for allowing me to re-open this topic.
@technoweenie,

then what is the advantage of using send(@person.send :age) over
@person.age? I tried searching for explanation but found none so far.

technoweenie wrote in post #4569:
> On 11/23/05, Jeff Cohen <cohen.jeff@gmail.com> wrote:
>>
>> Thanks!
>
> #send is inherited from Object:
>
> http://ruby-doc.org/core/classes/Object.html#M000998
>
> These statements are equal:
>
> @person.age
> @person.send :age
>
> @person.age = 5
> @person.send :age=, 5
>
> @person.set_age(5)
> @person.send :set_age, 5
>
>
> --
> rick
> http://techno-weenie.net
C03894f9fedea78a4823b21199116f8d?d=identicon&s=25 Tarun Mahajan (tango4567)
on 2017-02-22 18:18
Sorry for posting my question here. I'm fresher in this. Please help me
to run this command.
I'm notable to install json using gem, even gem is install properly.
Every time I'm getting same error.
Might be that's an silly mistake please help me out.

Thanks in advance.

input
""gem install json -v '1.8.6'""

output
Building native extensions.  This could take a while...
ERROR:  Error installing json:
  ERROR: Failed to build gem native extension.

    current directory:
/var/lib/gems/2.3.0/gems/json-1.8.6/ext/json/ext/generator
/usr/bin/ruby2.3 -r ./siteconf20170222-14108-ee0y5j.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/json-1.8.6
for inspection.
Results logged to
/var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/json-1.8.6/gem_make.out
0f4e3c4b24c489a3c0c66e8dde07dac3?d=identicon&s=25 Karta Larchmont (kel)
on 2017-02-22 23:23
My sneaking suspicion is that it is missing a dependency somewhere,
assuming that ruby.h is where it is supposed to be.

For example: Just the other day, and for months earlier, I was unable to
compile json on this ancient 32 bit XP machine with DevKit. Ruby 193

I installed about a thousand files from an old mirror (with --force) and
then for $hits and giggles tried:

gem install json

After whirling and sputtering for a moment it came up with:

Successfully installed json-2.03
C03894f9fedea78a4823b21199116f8d?d=identicon&s=25 Tarun Mahajan (tango4567)
on 2017-02-26 19:29
Thank You Karta



Karta Larchmont wrote in post #1185588:
> My sneaking suspicion is that it is missing a dependency somewhere,
> assuming that ruby.h is where it is supposed to be.
>
> For example: Just the other day, and for months earlier, I was unable to
> compile json on this ancient 32 bit XP machine with DevKit. Ruby 193
>
> I installed about a thousand files from an old mirror (with --force) and
> then for $hits and giggles tried:
>
> gem install json
>
> After whirling and sputtering for a moment it came up with:
>
> Successfully installed json-2.03
This topic is locked and can not be replied to.