Ask a Question related to Ruby, Design and Development.
-
Aryeh Friedman #1
dynamic object creation
If I have something like this:
s="Array"
How whould I get something like this:
aObject=s.new
In "plain" english I am asking if I have a valid name of a class in a
string how do I create an instance of the class the string contains?
Aryeh Friedman Guest
-
dynamic xml creation
How can I make XML dynamically inside tha Flash using AS? Basicly i need to make structure like these one: <root> <item></item> ...... -
Dynamic DataGridRow creation
Dear all, I am working with a datagrid populated by an XML via a WebService and I would like to populate my dataGrid dynamicaly (as I browse the... -
dynamic tag creation
Looking for a way to dynamically evaluate a tag from a string. eg: <cfset tmp = '<cfset myRslt = "Hello">'> <cfoutput> #tmp# </cfoutput> ... -
Dynamic content creation
I'm rather a newbie to flex, at the stage of considering it it is worth my time to get to know to it (or maybe laszlo...). I have this question:... -
Dynamic Sprite Creation
Hi, I am writing a data driven application that reads a configuration file and populates a director stage with the content of the file. I am not... -
Simon Strandgaard #2
Re: dynamic object creation
On Mon, 30 Jun 2003 16:49:05 +0000, Aryeh Friedman wrote:
> If I have something like this:
>
> s="Array"
>
> How whould I get something like this:
>
> aObject=s.new
>
> In "plain" english I am asking if I have a valid name of a class in a
> string how do I create an instance of the class the string contains?
How about this ?
s="Array"
aObject=eval(s+".new")
--
Simon Strandgaard
Simon Strandgaard Guest
-
stefano #3
Re: dynamic object creation
On Mon, 30 Jun 2003 15:49:05 +0000, Aryeh Friedman wrote:
s = "Array"> If I have something like this:
>
> s="Array"
>
> How whould I get something like this:
>
> aObject=s.new
>
> In "plain" english I am asking if I have a valid name of a class in a
> string how do I create an instance of the class the string contains?
aObject = eval(s).new
--
ste
stefano Guest
-
Brian Candler #4
Re: dynamic object creation
On Tue, Jul 01, 2003 at 01:22:22AM +0900, stefano wrote:
... and just hope nobody passes in s = "`rm -rf /*`" as a class name :-|> On Mon, 30 Jun 2003 15:49:05 +0000, Aryeh Friedman wrote:
>>> > If I have something like this:
> >
> > s="Array"
> >
> > How whould I get something like this:
> >
> > aObject=s.new
> >
> > In "plain" english I am asking if I have a valid name of a class in a
> > string how do I create an instance of the class the string contains?
> s = "Array"
> aObject = eval(s).new
const_get will be much faster too, as it doesn't have to compile a piece of
code each time.
Brian Candler Guest
-
Dave Thomas #5
Re: dynamic object creation
John Platte wrote:
> On the page you referenced, the entry for const_defined? says it takes a
> symbol too, but the example code uses a string argument...!? Same for
> const_set.At the top of the section, you'll find "In the descriptions that follow,>> I just tested it and to my surprise it worked?!
>>
>> [url]http://rubycentral.com/book/ref_c_module.html#Module.const_get[/url]
>>
>> says that I need to supply a symbol, why does it accept a string?
the parameter aSymbol refers to a symbol, which is either a quoted
string or a Symbol (such as :name)."
Cheers
Dave
Dave Thomas Guest
-
John Platte #6
Re: dynamic object creation
[url]http://rubycentral.com/book/ref_c_module.htm[/url]
I spoke too soon. At the top of the page:
Sorry for the spurious post.> In the descriptions that follow, the parameter aSymbol refers to a
> symbol, which is either a quoted string or a Symbol (such as :name )
On Monday, Jun 30, 2003, at 15:33 America/Chicago, John Platte wrote:
--> On the page you referenced, the entry for const_defined? says it takes
> a symbol too, but the example code uses a string argument...!? Same
> for const_set.
>
> On Monday, Jun 30, 2003, at 15:23 America/Chicago, Anders Borch wrote:
>>>>>> A class name is just a constant, so something like
>>> a = Module.const_get("Array").new
>> uhm... why does this work?
>>
>> I just tested it and to my surprise it worked?!
>>
>> [url]http://rubycentral.com/book/ref_c_module.html#Module.const_get[/url]
>>
>> says that I need to supply a symbol, why does it accept a string?
>>
>> is this something that will continue to work in 1.8? (im still using
>> 1.6.8 on my winbox and 1.6.7 on my linux box)
John Platte
Principal Consultant, NIKA Consulting
[url]http://nikaconsulting.com/[/url]
(630) 499 9830
Fax: (630) 566 0655
John Platte Guest
-
Anders Borch #7
Re: dynamic object creation
Brian Candler wrote:
uhm... why does this work?> On Tue, Jul 01, 2003 at 01:01:25AM +0900, Aryeh Friedman wrote:
>>>>If I have something like this:
>>
>>s="Array"
>>
>>How whould I get something like this:
>>
>>aObject=s.new
>>
>>In "plain" english I am asking if I have a valid name of a class in a
>>string how do I create an instance of the class the string contains?
>
> A class name is just a constant, so something like
>
> a = Module.const_get("Array").new
I just tested it and to my surprise it worked?!
[url]http://rubycentral.com/book/ref_c_module.html#Module.const_get[/url]
says that I need to supply a symbol, why does it accept a string?
is this something that will continue to work in 1.8? (im still using
1.6.8 on my winbox and 1.6.7 on my linux box)
>
> is what you need (Aside: what's the proper way to access 'the top-level
> Module', or is the above correct?)
>
> Cheers,
>
> Brian.
>
--
dc -e
4dd*od3*dddn1-89danrn10-dan3+ann6*dan*2*an13dn1+dn2-dn3+5*ddan2/9+an13nap
Anders Borch Guest
-
Anders Borch #8
Re: dynamic object creation
Dave Thomas wrote:
thanks alot :) I'll try to *read* from now on ;)> John Platte wrote:
>>>> On the page you referenced, the entry for const_defined? says it takes
>> a symbol too, but the example code uses a string argument...!? Same
>> for const_set.
>>>>> I just tested it and to my surprise it worked?!
>>>
>>> [url]http://rubycentral.com/book/ref_c_module.html#Module.const_get[/url]
>>>
>>> says that I need to supply a symbol, why does it accept a string?
>
> At the top of the section, you'll find "In the descriptions that follow,
> the parameter aSymbol refers to a symbol, which is either a quoted
> string or a Symbol (such as :name)."
>
--
dc -e
4dd*od3*dddn1-89danrn10-dan3+ann6*dan*2*an13dn1+dn2-dn3+5*ddan2/9+an13nap
Anders Borch Guest
-
stefano #9
Re: dynamic object creation
On Tue, 01 Jul 2003 05:01:08 +0900, Brian Candler wrote:
obviously, if you don't check what you're passing to eval(), you deserve> .. and just hope nobody passes in s = "`rm -rf /*`" as a class name :-|
all the bad things that could happen :-)
that's true, I didn't think about it.> const_get will be much faster too, as it doesn't have to compile a piece of
> code each time.
--
ste
stefano Guest
-
Anders Borch #10
Re: dynamic object creation
Brian Candler wrote:
hadn't seen that one, thanks =)> On Tue, Jul 01, 2003 at 05:23:35AM +0900, Anders Borch wrote:
>>>>>>>A class name is just a constant, so something like
>>>
>>> a = Module.const_get("Array").new
>>uhm... why does this work?
>>
>>I just tested it and to my surprise it worked?!
>>
>>[url]http://rubycentral.com/book/ref_c_module.html#Module.const_get[/url]
>>
>>says that I need to supply a symbol, why does it accept a string?
>
> Even if it didn't, you can easily convert strings to symbols and vice versa.
>
> "Array".intern
> => :Array
> :Array.to_s
> => "Array"
>
> Regards,
>
> Brian.
>
--
dc -e
4dd*od3*dddn1-89danrn10-dan3+ann6*dan*2*an13dn1+dn2-dn3+5*ddan2/9+an13nap
Anders Borch Guest
-
Robert Klemme #11
Re: dynamic object creation
"Brian Candler" <B.Candler@pobox.com> schrieb im Newsbeitrag
news:20030630171414.A19372@linnet.org...I think this does it> On Tue, Jul 01, 2003 at 01:01:25AM +0900, Aryeh Friedman wrote:>> > If I have something like this:
> >
> > s="Array"
> >
> > How whould I get something like this:
> >
> > aObject=s.new
> >
> > In "plain" english I am asking if I have a valid name of a class in a
> > string how do I create an instance of the class the string contains?
> A class name is just a constant, so something like
>
> a = Module.const_get("Array").new
>
> is what you need (Aside: what's the proper way to access 'the top-level
> Module', or is the above correct?)
a = Kernel.const_get("Array").new
robert
Robert Klemme Guest



Reply With Quote

