Is there a way to store the actual code of a class or definition as a
string without manually doing it? Such as if you were doing a tutorial
on how something works. So basically I could do print aB and I get "def
code a = 5 b = 2 end"
Is there a way to store the actual code of a class or definition as a
string without manually doing it? Such as if you were doing a tutorial
on how something works. So basically I could do print aB and I get "def
code a = 5 b = 2 end"
Is there a way to store the actual code of a class or definition as a
string without manually doing it? Such as if you were doing a tutorial
on how something works. So basically I could do print aB and I get "def
code a = 5 b = 2 end"
Thanks, the code works, but is there still a way to print out everything
in a class by just referencing the class name? To get everything to be
displayed using this code it has to basicaly start before the class and
end afterward.
@ab = <<-CODE
class Ab
def code
a = 5
b = 2
end
CODE
eval(@ab)
def print_class(klass)
print instance_variable_get "@#{klass.to_s.downcase}"
end
print_class(Ab)
···
On 5/9/06, Patrick <strife045@hotmail.com> wrote:
Thanks, the code works, but is there still a way to print out everything
in a class by just referencing the class name? To get everything to be
displayed using this code it has to basicaly start before the class and
end afterward.
I was asking something similar about blocks in the near past. After a
fiery discussion I was advised tou use a ParseTree trick to go back to
the original code and read it..
···
On 5/9/06, Joey <rubytalk@eachmapinject.com> wrote:
@ab = <<-CODE
class Ab
def code
a = 5
b = 2
end
CODE
eval(@ab)
def print_class(klass)
print instance_variable_get "@#{klass.to_s.downcase}"
end
print_class(Ab)
On 5/9/06, Patrick <strife045@hotmail.com> wrote:
>
> Thanks, the code works, but is there still a way to print out everything
> in a class by just referencing the class name? To get everything to be
> displayed using this code it has to basicaly start before the class and
> end afterward.
>
> --
> Posted via http://www.ruby-forum.com/\.
>