[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: What's the difference between send and instance_eval?

Gavin Kistner

10/26/2006 7:24:00 PM

> I may not understand it well, but I don't like it. The two methods are
> so similar that the only way to figure out the difference is to find
> cases that will make it hard or impossible to use one of them. It
> should be easy to choose which method to use, not hard to figure out
> which one not to use.

OK, here you go:
* Use send when you want to invoke a method, but you have a variable
holding the name of a method.
* Use instance_eval when you want to muck about with the internals of an
object.


2 Answers

michele

10/26/2006 7:36:00 PM

0

Thanks alot, you nice Ruby-people.



One last question:

Is it the Ruby language that make programmers be good, or is it that
good people are drawn too the Ruby language?


On Oct 26, 9:24 pm, "Gavin Kistner" <gavin.kist...@anark.com> wrote:
> > I may not understand it well, but I don't like it. The two methods are
> > so similar that the only way to figure out the difference is to find
> > cases that will make it hard or impossible to use one of them. It
> > should be easy to choose which method to use, not hard to figure out
> > which one not to use.OK, here you go:
> * Use send when you want to invoke a method, but you have a variable
> holding the name of a method.
> * Use instance_eval when you want to muck about with the internals of an
> object.

Paul Lutus

10/26/2006 8:58:00 PM

0

michele wrote:

> One last question:
>
> Is it the Ruby language that make programmers be good, or is it that
> good people are drawn too the Ruby language?

Yes to one, maybe to the other, results not sorted. :)

In all seriousness, computer languages have historically tended to reflect
the intentions of their creators, and creating easy-to-use languages has
rarely been on anyone's radar screen, compared to issues of job security,
making oneself look brilliant, and locking out the unwashed masses.

Doctors until recently excluded the masses by speaking Latin, geeks exclude
the masses by speaking a kind of technical shorthand, one in which there is
an obscure computer term or instruction for every imaginable real-world
contingency (techy-wife to techy-husband at bedtime: "So, are we online
tonight or what?"). It's sort of like being a teenager your entire life.

There just aren't many languages that approach Ruby for readability, for a
reasonable correspondence between how people think and what can be executed
by the interpreter:

read(file) unless(busy_sleeping)

And there are only a certain number of programmers constitutionally disposed
to allow their code be this readable and transparent. At its most basic, it
is the difference between:

"I can solve your problem."

-- and --

"You can solve your problem."

--
Paul Lutus
http://www.ara...