[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

instance_eval vs. class_eval context

Andrew Gibson

8/10/2006 6:43:00 PM

Is it the same context when a class is the receiver of instance_eval or
class_eval/module_eval?


--
Posted via http://www.ruby-....

29 Answers

Arnaud Bergeron

8/11/2006 3:56:00 PM

0

On 8/10/06, Andrew Gibson <gibson_andrew@yahoo.com> wrote:
> Is it the same context when a class is the receiver of instance_eval or
> class_eval/module_eval?

No. In case of instance_eval you will be in the class, and in the
case of (class|module)_eval you will be in the class of the class
(which is Class) [Hurray for multiple meanings to a word!]

> Posted via http://www.ruby-....

--
"What is your function in life?" - Killer

ts

8/11/2006 4:14:00 PM

0

>>>>> "A" == Arnaud Bergeron <abergeron@gmail.com> writes:

A> No. In case of instance_eval you will be in the class, and in the
A> case of (class|module)_eval you will be in the class of the class
A> (which is Class) [Hurray for multiple meanings to a word!]

no, not really. ruby use self and internally ruby_class which give it
where it can define method when it find keyword like 'def', 'alias', ...

With obj.instance_eval ruby will make
* self = obj , ruby_class = obj singleton class

This mean that inside instance_eval it will define singleton method

#instance_eval work with any object, but a class is a little special
because it can be seen as an object or as a class. This is why
#module_eval, #class_eval exist.

With obj.class_eval ruby will make

* self = obj, ruby_class = obj

This mean that inside class_eval ruby will define instance method.

One way to see it

moulon% ruby -e 'class A; end; A.instance_eval{ p self; def a() puts "A::a" end}; A.a'
A
A::a
moulon%

moulon% ruby -e 'class A; end; A.class_eval{ p self; def a() puts "A#a" end}; A.new.a'
A
A#a
moulon%



Guy Decoux

James Gray

8/11/2006 4:48:00 PM

0

On Aug 11, 2006, at 11:14 AM, ts wrote:

>>>>>> "A" == Arnaud Bergeron <abergeron@gmail.com> writes:
>
> A> No. In case of instance_eval you will be in the class, and in the
> A> case of (class|module)_eval you will be in the class of the class
> A> (which is Class) [Hurray for multiple meanings to a word!]
>
> no, not really. ruby use self and internally ruby_class which give it
> where it can define method when it find keyword like 'def',
> 'alias', ...
>
> With obj.instance_eval ruby will make
> * self = obj , ruby_class = obj singleton class
>
> This mean that inside instance_eval it will define singleton method
>
> #instance_eval work with any object, but a class is a little special
> because it can be seen as an object or as a class. This is why
> #module_eval, #class_eval exist.
>
> With obj.class_eval ruby will make
>
> * self = obj, ruby_class = obj
>
> This mean that inside class_eval ruby will define instance method.
>
> One way to see it
>
> moulon% ruby -e 'class A; end; A.instance_eval{ p self; def a()
> puts "A::a" end}; A.a'
> A
> A::a
> moulon%
>
> moulon% ruby -e 'class A; end; A.class_eval{ p self; def a() puts
> "A#a" end}; A.new.a'
> A
> A#a
> moulon%

I've always had trouble understanding this and for some reason this
is the email that finally clicked all the pieces into place for me.
Thanks Guy!

James Edward Gray II


Dave Head

10/29/2010 9:49:00 PM

0

On Fri, 29 Oct 2010 07:13:56 -0700 (PDT), Harry K
<turnkey4099@hotmail.com> wrote:

>On Oct 29, 4:30 am, Dave__67 <spamTHIS...@yahoo.com> wrote:
>> On Oct 29, 6:59 am, Dave Head <rally...@att.net> wrote:
>>
>> >http://www.caradvice.com.au/89483/audi-a2-electric-vehicle-......
>>
>> > Maybe, if it doesn't cost a million dollars.  These guys have run a
>> > car for about 400 miles on a single battery charge at around 70 - 80
>> > mph.  That's awesome if true.  It could be America's way out of buying
>> > foreign oil, and greatly reducing ur operating costs.
>>
>> > My Subaru WRX gets 25 mpg on a typical long trip.  A Chevy Volt goes
>> > 40 miles on a 10 KwH charge.  Around here, 10 KwH costs 62 1/2 cents.
>> > The WRX takes premium and costs about $4.72 to go 40 miles.  Big
>> > difference.  Maybe we have cheap transportation again?  CAFE
>> > standards?  Unncessary.  And we have absolutely oceans of domestic
>> > natural gas to build clean power generation for these cars.
>>
>> > Just hope its real.
>>
>> liPos are great- use them in  my model airplane.
>> Very light, awesome capacity.
>>
>> They have a huge downside though- physical trauma tends to make them,
>> well, explode.
>> So does overcharging.
>>
>> They are also damaged if they are discharged beyond a certain point.
>>
>> Dave
>
>I haven't really dug into the electrics but I don't see them ever
>replacing IC powered, augmenting, yes. I would love to have one but
>it would have to be a 3rd vehicle and used just for local trips
>(within around 40 miles).

Howcum? Why would you not want to jump in it and drive it from, say,
New York to Las Vegas?

>I live in a sparsely populated farming
>rural area withing 4 miles of town but that town is less that 2,000
>pop and thus shopping is limited. Nearest real shopping (and it is
>not all that great) is a 60 mile round trip.

Well, they just drove this particular car 400 miles without refueling,
sooo... what's the problem?

>Electrics, even the current ones, should do fine in an urban setting
>but the price is going to have to come down.

Oh, yeah, the price has to come down... but the cost of fuel is a big
mitigating factor.

>
>Harry K

Brent P

10/29/2010 11:02:00 PM

0

On 2010-10-29, Dave Head <rally2xs@att.net> wrote:

> Oh, yeah, the price has to come down... but the cost of fuel is a big
> mitigating factor.

The issue I find is that the cost of electricity vs. the cost of
gasoline equation is generally rigged by not considering the taxes on
the electricity but including them on gasoline. Then there is the
question of taxes for roads which one way or another will be charged
towards electrics.


Dave Head

10/29/2010 11:05:00 PM

0

On Fri, 29 Oct 2010 23:01:31 +0000 (UTC), Brent
<tetraethylleadREMOVETHIS@yahoo.com> wrote:

>On 2010-10-29, Dave Head <rally2xs@att.net> wrote:
>
>> Oh, yeah, the price has to come down... but the cost of fuel is a big
>> mitigating factor.
>
>The issue I find is that the cost of electricity vs. the cost of
>gasoline equation is generally rigged by not considering the taxes on
>the electricity but including them on gasoline. Then there is the
>question of taxes for roads which one way or another will be charged
>towards electrics.

They're gonna have a hard time collecting road taxes from electrics,
aren't they?

Probably dump the road tax concept, just pay for it with general
taxes.

Brent P

10/29/2010 11:13:00 PM

0

On 2010-10-29, Dave Head <rally2xs@att.net> wrote:
> On Fri, 29 Oct 2010 23:01:31 +0000 (UTC), Brent
><tetraethylleadREMOVETHIS@yahoo.com> wrote:
>
>>On 2010-10-29, Dave Head <rally2xs@att.net> wrote:
>>
>>> Oh, yeah, the price has to come down... but the cost of fuel is a big
>>> mitigating factor.
>>
>>The issue I find is that the cost of electricity vs. the cost of
>>gasoline equation is generally rigged by not considering the taxes on
>>the electricity but including them on gasoline. Then there is the
>>question of taxes for roads which one way or another will be charged
>>towards electrics.
>
> They're gonna have a hard time collecting road taxes from electrics,
> aren't they?
>
> Probably dump the road tax concept, just pay for it with general
> taxes.

No, the loving government has a concept by which they will expand their
power. They are playing with tax by the mile GPS tracking systems.


harry k

10/30/2010 4:26:00 AM

0

On Oct 29, 2:49 pm, Dave Head <rally...@att.net> wrote:
> On Fri, 29 Oct 2010 07:13:56 -0700 (PDT), Harry K
>
>
>
>
>
> <turnkey4...@hotmail.com> wrote:
> >On Oct 29, 4:30 am, Dave__67 <spamTHIS...@yahoo.com> wrote:
> >> On Oct 29, 6:59 am, Dave Head <rally...@att.net> wrote:
>
> >> >http://www.caradvice.com.au/89483/audi-a2-electric-vehicle-.......
>
> >> > Maybe, if it doesn't cost a million dollars. These guys have run a
> >> > car for about 400 miles on a single battery charge at around 70 - 80
> >> > mph. That's awesome if true. It could be America's way out of buying
> >> > foreign oil, and greatly reducing ur operating costs.
>
> >> > My Subaru WRX gets 25 mpg on a typical long trip. A Chevy Volt goes
> >> > 40 miles on a 10 KwH charge. Around here, 10 KwH costs 62 1/2 cents.
> >> > The WRX takes premium and costs about $4.72 to go 40 miles. Big
> >> > difference. Maybe we have cheap transportation again? CAFE
> >> > standards? Unncessary. And we have absolutely oceans of domestic
> >> > natural gas to build clean power generation for these cars.
>
> >> > Just hope its real.
>
> >> liPos are great- use them in my model airplane.
> >> Very light, awesome capacity.
>
> >> They have a huge downside though- physical trauma tends to make them,
> >> well, explode.
> >> So does overcharging.
>
> >> They are also damaged if they are discharged beyond a certain point.
>
> >> Dave
>
> >I haven't really dug into the electrics but I don't see them ever
> >replacing IC powered, augmenting, yes.  I would love to have one but
> >it would have to be a 3rd vehicle and used just for local trips
> >(within around 40 miles).
>
> Howcum?  Why would you not want to jump in it and drive it from, say,
> New York to Las Vegas?

Right after you. You are aware we are discussing _electric_ cars?

>
> >I live in a sparsely populated farming
> >rural area withing 4 miles of town but that town is less that 2,000
> >pop and thus shopping is limited.  Nearest real shopping (and it is
> >not all that great) is a 60 mile round trip.
>
> Well, they just drove this particular car 400 miles without refueling,
> sooo... what's the problem?
>

"this car"? Care to give a cite. I am sure they did it but I'll bet
they did some things that aren't practical.

And people have driven IC cars to get extremely high mileage. Their
methods would not be allowed in normal traffic.

> >Electrics, even the current ones, should do fine in an urban setting
> >but the price is going to have to come down.
>
> Oh, yeah, the price has to come down... but the  cost of fuel is a big
> mitigating factor.
>

As is replacing a battery pack and you still wind up with limited
range.

Harry K

harry k

10/30/2010 4:28:00 AM

0

On Oct 29, 4:04 pm, Dave Head <rally...@att.net> wrote:
> On Fri, 29 Oct 2010 23:01:31 +0000 (UTC), Brent
>
> <tetraethylleadREMOVET...@yahoo.com> wrote:
> >On 2010-10-29, Dave Head <rally...@att.net> wrote:
>
> >> Oh, yeah, the price has to come down... but the  cost of fuel is a big
> >> mitigating factor.
>
> >The issue I find is that the cost of electricity vs. the cost of
> >gasoline equation is generally rigged by not considering the taxes on
> >the electricity but including them on gasoline. Then there is the
> >question of taxes for roads which one way or another will be charged
> >towards electrics.
>
> They're gonna have a hard time collecting road taxes from electrics,
> aren't they?
>

Ever see the government having a hard time collect a tax they really
want? It is already proposed to charge mileage fees for regular
vehicles, why not electics?

> Probably dump the road tax concept, just pay for it with general
> taxes.

Harry K

Dave Head

10/30/2010 9:08:00 AM

0

On Fri, 29 Oct 2010 21:25:44 -0700 (PDT), Harry K
<turnkey4099@hotmail.com> wrote:

>On Oct 29, 2:49 pm, Dave Head <rally...@att.net> wrote:
>> On Fri, 29 Oct 2010 07:13:56 -0700 (PDT), Harry K
>>
>>
>>
>>
>>
>> <turnkey4...@hotmail.com> wrote:
>> >On Oct 29, 4:30 am, Dave__67 <spamTHIS...@yahoo.com> wrote:
>> >> On Oct 29, 6:59 am, Dave Head <rally...@att.net> wrote:
>>
>> >> >http://www.caradvice.com.au/89483/audi-a2-electric-vehicle-......
>>
>> >> > Maybe, if it doesn't cost a million dollars. These guys have run a
>> >> > car for about 400 miles on a single battery charge at around 70 - 80
>> >> > mph. That's awesome if true. It could be America's way out of buying
>> >> > foreign oil, and greatly reducing ur operating costs.
>>
>> >> > My Subaru WRX gets 25 mpg on a typical long trip. A Chevy Volt goes
>> >> > 40 miles on a 10 KwH charge. Around here, 10 KwH costs 62 1/2 cents.
>> >> > The WRX takes premium and costs about $4.72 to go 40 miles. Big
>> >> > difference. Maybe we have cheap transportation again? CAFE
>> >> > standards? Unncessary. And we have absolutely oceans of domestic
>> >> > natural gas to build clean power generation for these cars.
>>
>> >> > Just hope its real.
>>
>> >> liPos are great- use them in my model airplane.
>> >> Very light, awesome capacity.
>>
>> >> They have a huge downside though- physical trauma tends to make them,
>> >> well, explode.
>> >> So does overcharging.
>>
>> >> They are also damaged if they are discharged beyond a certain point.
>>
>> >> Dave
>>
>> >I haven't really dug into the electrics but I don't see them ever
>> >replacing IC powered, augmenting, yes.  I would love to have one but
>> >it would have to be a 3rd vehicle and used just for local trips
>> >(within around 40 miles).
>>
>> Howcum?  Why would you not want to jump in it and drive it from, say,
>> New York to Las Vegas?
>
>Right after you. You are aware we are discussing _electric_ cars?

Yeah. You did read the original post of this thread, right?
>
>>
>> >I live in a sparsely populated farming
>> >rural area withing 4 miles of town but that town is less that 2,000
>> >pop and thus shopping is limited.  Nearest real shopping (and it is
>> >not all that great) is a 60 mile round trip.
>>
>> Well, they just drove this particular car 400 miles without refueling,
>> sooo... what's the problem?
>>
>
>"this car"? Care to give a cite. I am sure they did it but I'll bet
>they did some things that aren't practical.

Its in the original post of this thread.

>And people have driven IC cars to get extremely high mileage. Their
>methods would not be allowed in normal traffic.

No, they just chugged down the highway like any other car.

>> >Electrics, even the current ones, should do fine in an urban setting
>> >but the price is going to have to come down.
>>
>> Oh, yeah, the price has to come down... but the  cost of fuel is a big
>> mitigating factor.
>>
>
>As is replacing a battery pack and you still wind up with limited
>range.

So? You have limited range in a regular car too, until you fill the
gas tank again...

>
>Harry K