#
# module FooTest
# @@foo=["a","b","c"]
#
# def mfoo
# @@foo.each do |f|
# p f
# end
# end
# end
#
#"@@foo" can be accessed from anywhere in the FooTest body.
yes, sir Matz. I've already also tried that and I like class vars. But how
can I answer my peer's question, "duh, and your telling us to change our
sh/perl scripts to that? I thought you said ruby is easy to our eyes and
brain, botp?" ?
my humble request is: can we not extend "locals" to embrace scope outside so
they may act like class vars?
something like this i want if possible,
# script.rb #---------------------
classvar x # maybe, we may declare x as a class local var (just my term)
# as if x now has nature like @@x
x=1
def mx1
p x #-> 1
end
p x #-> 1
def mx2
x = 2 # same x updated
p x #-> 2
end
p x #-> 2
It is really @@x but without the @@.
I hope i am not asking too much
Again, thank you for answering newbie questions like this.
It would require declarations, I think. Ruby is, for the most part, a
declaration-free language. This is matz choice. Instead you can tell
what a thing is by how it looks: "Class", "Module" or "Constant",
"@@class_var", "@instance_var", "$global_var, "method" or "local_var".
It's probably a very good thing that globals have a visual clue. As for
the others, I sometimes think not. Yes, knowing what a thing is right
off is nice, but the perlishness is hard on the eye.
yes, sir Matz. I've already also tried that and I like class vars. But how
can I answer my peer's question, "duh, and your telling us to change our
sh/perl scripts to that? I thought you said ruby is easy to our eyes and
brain, botp?" ?
my humble request is: can we not extend "locals" to embrace scope outside so
they may act like class vars?
something like this i want if possible,
# script.rb #---------------------
classvar x # maybe, we may declare x as a class local var (just my term)
# as if x now has nature like @@x
x=1
def mx1
p x #-> 1
end
p x #-> 1
def mx2
x = 2 # same x updated
p x #-> 2
end
p x #-> 2
It is really @@x but without the @@.
I hope i am not asking too much
You say that you are converting Perl code, which is usually full of
$'s and @'s, so this probably looks no worse than what you would
have converted it from:
In message "Re: [newbie] make local var visible" on Sat, 30 Jul 2005 11:20:09 +0900, "Peña, Botp" <botp@delmonte-phil.com> writes:
yes, sir Matz. I've already also tried that and I like class vars. But how
can I answer my peer's question, "duh, and your telling us to change our
sh/perl scripts to that? I thought you said ruby is easy to our eyes and
brain, botp?" ?
Even it is easy to our eyes and brain, I don't think it means ruby is
easy to port perl script. If one feels comfortable in Perl way, and
is not ready to change his way, he must stay in Perl.
It would require declarations, I think. Ruby is, for the most part, a
declaration-free language. This is matz choice. Instead you can tell
what a thing is by how it looks: "Class", "Module" or "Constant",
"@@class_var", "@instance_var", "$global_var, "method" or "local_var".
It's probably a very good thing that globals have a visual clue. As for
the others, I sometimes think not. Yes, knowing what a thing is right
off is nice, but the perlishness is hard on the eye.
I think you're giving Perl too much power and reach if you allow all
such things to be condemned because they're "perlish" Anyway, all
you have to do is avoid globals and be very economical with class
variables, and you're basically down to var and @var