What does ActiveRecord#send do?


#1

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!


#2

On 11/23/05, Jeff C. removed_email_address@domain.invalid 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


#3

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.


#4

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 C. removed_email_address@domain.invalid 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


#5

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


#6

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


#7

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