[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

object to class...

Pokkai Dokkai

10/10/2007 6:24:00 AM

is it possible to convert from a ruby object to Ruby class...
any idea.....
--
Posted via http://www.ruby-....

10 Answers

Alex Gutteridge

10/10/2007 7:40:00 AM

0

On 10 Oct 2007, at 15:24, Pokkai Dokkai wrote:

> is it possible to convert from a ruby object to Ruby class...
> any idea.....
> --
> Posted via http://www.ruby-....

I'm not sure what you mean, but every Object has a class method which
gives you it's class.

irb(main):008:0> 1.class
=> Fixnum
irb(main):009:0> 'foo'.class
=> String

Alex Gutteridge

Bioinformatics Center
Kyoto University



Sylvain Joyeux

10/10/2007 8:03:00 AM

0

On Wednesday 10 October 2007, Pokkai Dokkai wrote:
> is it possible to convert from a ruby object to Ruby class...
> any idea.....
What do you exactly have in mind ? Ruby classes are already Ruby
objects ... so if you need to manipulate classes as objects you already
can

obj = Class.new

<manipulate obj>

instance = obj.new

Sylvain

Shai Rosenfeld

10/10/2007 8:22:00 AM

0

Pokkai Dokkai wrote:
> is it possible to convert from a ruby object to Ruby class...
> any idea.....

do u mean this?

http://www.ruby-doc.org/core/classes/Object.ht...
--
Posted via http://www.ruby-....

Pokkai Dokkai

10/10/2007 10:47:00 AM

0

Sylvain Joyeux wrote:
> On Wednesday 10 October 2007, Pokkai Dokkai wrote:
>> is it possible to convert from a ruby object to Ruby class...
>> any idea.....
> What do you exactly have in mind ? Ruby classes are already Ruby
> objects ... so if you need to manipulate classes as objects you already
> can
>
> obj = Class.new
>
> <manipulate obj>
>
> instance = obj.new
>
> Sylvain

source code here
---------------------
class Name
def initialize
end
.....
end
-----------------------

obj=Name.new

now my question is ,how to create above source code ?.



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

Pokkai Dokkai

10/10/2007 10:50:00 AM

0

source code here
---------------------
class Name
def initialize
end
.....
end
-----------------------

obj=Name.new

now my question is ,how to create above source code from obj?.

actually jruby will create java object to ruby object
but that ruby object(from java object) is not in source code format

so i am asking this question ......
--
Posted via http://www.ruby-....

Robert Klemme

10/10/2007 10:52:00 AM

0

2007/10/10, Pokkai Dokkai <bad_good_lion@yahoo.com>:
> Sylvain Joyeux wrote:
> > On Wednesday 10 October 2007, Pokkai Dokkai wrote:
> >> is it possible to convert from a ruby object to Ruby class...
> >> any idea.....
> > What do you exactly have in mind ? Ruby classes are already Ruby
> > objects ... so if you need to manipulate classes as objects you already
> > can
> >
> > obj = Class.new
> >
> > <manipulate obj>
> >
> > instance = obj.new
> >
> > Sylvain
>
> source code here
> ---------------------
> class Name
> def initialize
> end
> .....
> end
> -----------------------
>
> obj=Name.new
>
> now my question is ,how to create above source code ?.

If you want to create the class definition source code when having an
instance only there is no way - at least no standard way. You would
have to dig into the Ruby interpreter to do that.

robert

Ari Brown

10/10/2007 11:27:00 AM

0


On Oct 10, 2007, at 4:22 AM, Shai Rosenfeld wrote:

> Pokkai Dokkai wrote:
>> is it possible to convert from a ruby object to Ruby class...
>> any idea.....
>
> do u mean this?
>
> http://www.ruby-doc.org/core/classes/Object.ht...

Maybe he means something like extracting Ruby code for the class out
of the object... That would be very interesting, because you could
really delve in and affect all sorts of bug fixes for compiled
extensions.

AFAIK, this is not possible. Take a look at ruby2ruby

I'm guessing something like

a = YourClass.new
a.to_ruby

Ari
--------------------------------------------|
If you're not living on the edge,
then you're just wasting space.



Peña, Botp

10/11/2007 2:10:00 AM

0

From: Ari Brown [mailto:ari@aribrown.com]
# AFAIK, this is not possible. Take a look at ruby2ruby

cool

# I'm guessing something like
#
# a = YourClass.new
# a.to_ruby

arggh, i'm feeling dumb, i've just downloaded the gem, but i do not know how to require it. The rdoc does not give an example.

kind regards -botp

Peña, Botp

10/11/2007 2:25:00 AM

0

From: Peña, Botp [mailto:botp@delmonte-phil.com]
# arggh, i'm feeling dumb, i've just downloaded the gem, but i
# do not know how to require it. The rdoc does not give an example.

pls ignore. dumb indeed. forgot the 'rubygems' require. gotta change my irb ini.

my next question is, will this run on windows?
if yes, examples pls.

thanks and kind regards -botp



John Joyce

10/12/2007 9:38:00 AM

0


On Oct 10, 2007, at 5:50 AM, Pokkai Dokkai wrote:

> source code here
> ---------------------
> class Name
> def initialize
> end
> .....
> end
> -----------------------
>
> obj=Name.new
>
> now my question is ,how to create above source code from obj?.
>
> actually jruby will create java object to ruby object
> but that ruby object(from java object) is not in source code format
>
> so i am asking this question ......
> --
> Posted via http://www.ruby-....
>

Well, it could be sort of possible, but partly pointless:
You could start a ruby process that then loads a file, but before
loading, read the file. You could then create objects that contain
the code (as a string, probably) for classes in the original file.
Then when you ask an object, "what class are you?", you will have a
little clipboard (or PDA) to lookup his/her class name and fetch your
class_code string.

From there it would be possible to alter the class_code string, then
re"load" that class into the interpreter...
circular? could be
pointless? maybe
fun? probably