object to class...

A

Alex Gutteridge

is it possible to convert from a ruby object to Ruby class...
any idea.....

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
 
S

Sylvain Joyeux

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
 
P

Pokkai Dokkai

Sylvain said:
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
 
P

Pokkai Dokkai

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 ......
 
R

Robert Klemme

2007/10/10 said:
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
 
A

Ari Brown


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.
 
P

Peña, Botp

From: Ari Brown [mailto:[email protected]]=20
# AFAIK, this is not possible. Take a look at ruby2ruby

cool

# I'm guessing something like
#=20
# a =3D 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
 
P

Peña, Botp

From: Pe=F1a, Botp [mailto:[email protected]]=20
# arggh, i'm feeling dumb, i've just downloaded the gem, but i=20
# 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
 
J

John Joyce

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 ......

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top