[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

create a class in a class with eval

Gaspard Bucher

9/25/2007 12:18:00 PM

I need to eval code that will create globally available classes. I tried this :

class Test
def makeA
Module.send(:eval, "class A; end")
# same with: eval "class A; end"
puts Test.const_get('A') # => Test::A
puts Module.const_get('A') # => raise NameError, why ?
end
end

eval "class B; end"
puts Module.const_get('B') # => B

Test.new.makeA #=> bang

Thanks for your help.

Gaspard

6 Answers

David A. Black

9/25/2007 12:45:00 PM

0

Gaspard Bucher

9/25/2007 2:18:00 PM

0

Thanks for the answer. Works great.

I just changed Module to Object since:
Object.const_set("A", Class.new) ==> A
Module.const_set("A", Class.new) ==> Module::A

2007/9/25, David A. Black <dblack@rubypal.com>:
> Hi --
>
> On Tue, 25 Sep 2007, Gaspard Bucher wrote:
>
> > I need to eval code that will create globally available classes. I tried this :
> >
> > class Test
> > def makeA
> > Module.send(:eval, "class A; end")
> > # same with: eval "class A; end"
> > puts Test.const_get('A') # => Test::A
> > puts Module.const_get('A') # => raise NameError, why ?
> > end
> > end
> >
> > eval "class B; end"
> > puts Module.const_get('B') # => B
> >
> > Test.new.makeA #=> bang
>
> You could do:
>
> Module.module_eval "class A; end"
>
> or (preferable, in my opinion):
>
> Module.const_set("A", Class.new)
>
>
> David
>
> --
> Upcoming training from Ruby Power and Light, LLC:
> * Intro to Ruby on Rails, Edison, NJ, October 23-26
> * Advancing with Rails, Edison, NJ, November 6-9
> Both taught by David A. Black.
> See http://www.r... for more info!
>
>

Kerryn Offord

5/2/2011 1:11:00 AM

0

On 5/2/2011 6:44 AM, Ray Fischer wrote:
> Kerryn Offord<kao16@uclive.ac.nz> wrote:
>> On 5/1/2011 6:41 PM, Ray Fischer wrote:
>>> Catawumpus<kimmerian@fastmail.fm> wrote:
>>>> rfischer@sonic.net (Ray Fischer):
>>>>
>>>>> It's easy to insist that Israel is a democracy if you just pretend
>>>>> that everybody under Israeli rule who doesn't have rights doesn't
>>>>> actually exist.
>>>>
>>>> Israel is a democracy in the usual sense:
>>>
>>> Except for a million+ people under Israeli rule who have no vote.
>>
>> Funny.. Didn't they get to vote Hamas in in Gaza?
>
> Gaza is a large concentration camp controlled by Israel.
>
>> And Fatah in the West bank..
>
> The West Bank is ruled by Israel.
>
>> They don't want to be Israeli citizens,
>
> Israel does not allow them citizenship.
>
You got any evidence for that?

There are plenty of Palestinians with Israeli citizenship

ADR

5/2/2011 3:51:00 AM

0

On May 1, 6:11 pm, Kerryn Offord <ka...@uclive.ac.nz> wrote:
> On 5/2/2011 6:44 AM, Ray Fischer wrote:
>
>
>
>
>
>
>
> > Kerryn Offord<ka...@uclive.ac.nz>  wrote:
> >> On 5/1/2011 6:41 PM, Ray Fischer wrote:
> >>> Catawumpus<kimmer...@fastmail.fm>   wrote:
> >>>> rfisc...@sonic.net (Ray Fischer):
>
> >>>>> It's easy to insist that Israel is a democracy if you just pretend
> >>>>> that everybody under Israeli rule who doesn't have rights doesn't
> >>>>> actually exist.
>
> >>>>       Israel is a democracy in the usual sense:
>
> >>> Except for a million+ people under Israeli rule who have no vote.
>
> >> Funny.. Didn't they get to vote Hamas in in Gaza?
>
> > Gaza is a large concentration camp controlled by Israel.
>
> >> And Fatah in the West bank..
>
> > The West Bank is ruled by Israel.
>
> >> They don't want to be Israeli citizens,
>
> > Israel does not allow them citizenship.
>
> You got any evidence for that?
>
> There are plenty of Palestinians with Israeli citizenship

Arabs within the pre-1967 borders were granted citizenship but they
are certainly 2nd category citizens. Palestinians of the occupied
territories are actually forbidden to obtain Israeli citizenship with
a variety of prohibitions of the Israeli Citizenship Law. I think
that you know this quite well. Although Israel has the right to
dispose of property in the occupied territories as it sees fit, the
inhabitants have absolutely no say (as the occupied scum they are).

Kerryn Offord

5/2/2011 4:22:00 AM

0

On 5/2/2011 3:51 PM, ADR wrote:
> On May 1, 6:11 pm, Kerryn Offord<ka...@uclive.ac.nz> wrote:
>> On 5/2/2011 6:44 AM, Ray Fischer wrote:
>>
>>
>>
>>
>>
>>
>>
>>> Kerryn Offord<ka...@uclive.ac.nz> wrote:
>>>> On 5/1/2011 6:41 PM, Ray Fischer wrote:
>>>>> Catawumpus<kimmer...@fastmail.fm> wrote:
>>>>>> rfisc...@sonic.net (Ray Fischer):
>>
>>>>>>> It's easy to insist that Israel is a democracy if you just pretend
>>>>>>> that everybody under Israeli rule who doesn't have rights doesn't
>>>>>>> actually exist.
>>
>>>>>> Israel is a democracy in the usual sense:
>>
>>>>> Except for a million+ people under Israeli rule who have no vote.
>>
>>>> Funny.. Didn't they get to vote Hamas in in Gaza?
>>
>>> Gaza is a large concentration camp controlled by Israel.
>>
>>>> And Fatah in the West bank..
>>
>>> The West Bank is ruled by Israel.
>>
>>>> They don't want to be Israeli citizens,
>>
>>> Israel does not allow them citizenship.
>>
>> You got any evidence for that?
>>
>> There are plenty of Palestinians with Israeli citizenship
>
> Arabs within the pre-1967 borders were granted citizenship but they
> are certainly 2nd category citizens. Palestinians of the occupied
> territories are actually forbidden to obtain Israeli citizenship with
> a variety of prohibitions of the Israeli Citizenship Law. I think
> that you know this quite well. Although Israel has the right to
> dispose of property in the occupied territories as it sees fit, the
> inhabitants have absolutely no say (as the occupied scum they are).


Your choice of words indicates your agenda, which destroys the
credibility of anything you claim.

What evidence do you offer that the Arabs are second class citizens?

What evidence of any of your claims do you have?

ADR

5/2/2011 4:44:00 AM

0

On May 1, 9:21 pm, Kerryn Offord <ka...@uclive.ac.nz> wrote:
> On 5/2/2011 3:51 PM, ADR wrote:
>
>
>
>
>
>
>
>
>
> > On May 1, 6:11 pm, Kerryn Offord<ka...@uclive.ac.nz>  wrote:
> >> On 5/2/2011 6:44 AM, Ray Fischer wrote:
>
> >>> Kerryn Offord<ka...@uclive.ac.nz>    wrote:
> >>>> On 5/1/2011 6:41 PM, Ray Fischer wrote:
> >>>>> Catawumpus<kimmer...@fastmail.fm>     wrote:
> >>>>>> rfisc...@sonic.net (Ray Fischer):
>
> >>>>>>> It's easy to insist that Israel is a democracy if you just pretend
> >>>>>>> that everybody under Israeli rule who doesn't have rights doesn't
> >>>>>>> actually exist.
>
> >>>>>>        Israel is a democracy in the usual sense:
>
> >>>>> Except for a million+ people under Israeli rule who have no vote.
>
> >>>> Funny.. Didn't they get to vote Hamas in in Gaza?
>
> >>> Gaza is a large concentration camp controlled by Israel.
>
> >>>> And Fatah in the West bank..
>
> >>> The West Bank is ruled by Israel.
>
> >>>> They don't want to be Israeli citizens,
>
> >>> Israel does not allow them citizenship.
>
> >> You got any evidence for that?
>
> >> There are plenty of Palestinians with Israeli citizenship
>
> > Arabs within the pre-1967 borders were granted citizenship but they
> > are certainly 2nd category citizens.  Palestinians of the occupied
> > territories are actually forbidden to obtain Israeli citizenship with
> > a variety of prohibitions of the Israeli Citizenship Law.  I think
> > that you know this quite well.  Although Israel has the right to
> > dispose of property in the occupied territories as it sees fit, the
> > inhabitants have absolutely no say (as the occupied scum they are).
>
> Your choice of words indicates your agenda, which destroys the
> credibility of anything you claim.
>
> What evidence do you offer that the Arabs are  second class citizens?
>
> What evidence of any of your claims do you have?

No Arab can occupy any senior commands in the army or security
apparatus of Israel. Why is it difficult for you to accept that
Israel is a sectarian state? It is, by the definitions employed in
the Citizenship Law, as you should well know.

Having the vote is really meaningless is laws and constitution make it
impossible for members of a minority to achieve controlling positions
in a given state. This state is a true apartheid state.