Is there a way to look at the source of a class? E.g.
class Foo
def bar
# something
end
def foo
# something else
end
end
[0] Foo.source
=>class Foo
def bar
# something
end
def foo
# something else
end
end
[1]
Even being able to look at a method's source would be helpful, e.g.
[2] Foo.bar.source
=> def bar
# something
end
[3]
Pretty printing is not necessary. I've looked at the built-in classes
and modules and at tha standard library, and haven't been able to find
anything related to this. If there is no way to do such thing then a
simple "no" is sufficient, I'm just curious as to whether it is
possible or not. Cheers!
-CWS
Not without going back to the actual source files. Ruby does not keep
any form of the source itself around after parsing.
-austin
···
On Mon, 19 Jul 2004 02:24:39 +0900, Claus Spitzer <docboobenstein@gmail.com> wrote:
Is there a way to look at the source of a class? E.g.
Alright, understandable. Now the one question that remains (sorry for
being nit-picky) is if it would be possible to desonstruct objects.
After all, there has to be some place (possibly the metaclass) where
it says that Foo.bar
class Foo
def bar( in )
in + 1
end
end
does in+1, right? Cheers
-CWS
···
On Mon, 19 Jul 2004 04:51:46 +0900, Austin Ziegler <halostatue@gmail.com> wrote:
On Mon, 19 Jul 2004 02:24:39 +0900, Claus Spitzer > <docboobenstein@gmail.com> wrote:
> Is there a way to look at the source of a class? E.g.
Not without going back to the actual source files. Ruby does not keep
any form of the source itself around after parsing.
-austin
I'm not understanding your question. Ruby interprets the code into an
AST; if you know how to read the AST, then you may be able to figure
that out. However, you're not going to be able to do that in Ruby
"proper" (you'll need something like evil.rb which uses Ruby/DL, or
some of the other tools out there).
-austin
···
On Mon, 19 Jul 2004 05:24:52 +0900, Claus Spitzer <docboobenstein@gmail.com> wrote:
Alright, understandable. Now the one question that remains (sorry for
being nit-picky) is if it would be possible to desonstruct objects.
After all, there has to be some place (possibly the metaclass) where
it says that Foo.bar
class Foo
def bar( in )
in + 1
end
end
does in+1, right? Cheers
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca
Aha. I'll look into it, thanks.
···
On Mon, 19 Jul 2004 05:54:48 +0900, Austin Ziegler <halostatue@gmail.com> wrote:
On Mon, 19 Jul 2004 05:24:52 +0900, Claus Spitzer > <docboobenstein@gmail.com> wrote:
> Alright, understandable. Now the one question that remains (sorry for
> being nit-picky) is if it would be possible to desonstruct objects.
> After all, there has to be some place (possibly the metaclass) where
> it says that Foo.bar
>
> class Foo
> def bar( in )
> in + 1
> end
> end
>
> does in+1, right? Cheers
I'm not understanding your question. Ruby interprets the code into an
AST; if you know how to read the AST, then you may be able to figure
that out. However, you're not going to be able to do that in Ruby
"proper" (you'll need something like evil.rb which uses Ruby/DL, or
some of the other tools out there).
-austin
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca