N
Nicholas Paul Johnson
Hello again,
First is, does Ruby have anything equivalent to C++'s `this' pointer?
I've tried the docs, but don't know what to look for other than 'this'...
Second, if I were to write a method that accepts a block, and would like
to be able to recurse in that method while allowing each of the recursions
to use the same block, how would I do that?
As an example, suppose I have a tree data structure (below), such that
each node has two children: a and b. I want to create an ``each'' method.
Ideally, I would yield with ``this,'' and then would recurse to ``each''
on every child of that node.
# this doesnt work for so many reasons
class Node
def initialize(me,a,b)
@me = me
@a = a
@b = b
end
def each
# @this represents the calling object (see 1st question)
yield @this
# ideally, the same block would get passed to each of
# these sub calls
@aB.each
@b.each
end
end
Thanks y'all,
--
Nicholas Paul Johnson
nickjohnsonSPAM^H^H^H^[email protected]
http://manjac.ath.cx/nick
_
( ) ascii ribbon campaign - against html mail
X - against microsoft attachments
/ \ http://www.google.com/search?q=ascii+ribbon
--
First is, does Ruby have anything equivalent to C++'s `this' pointer?
I've tried the docs, but don't know what to look for other than 'this'...
Second, if I were to write a method that accepts a block, and would like
to be able to recurse in that method while allowing each of the recursions
to use the same block, how would I do that?
As an example, suppose I have a tree data structure (below), such that
each node has two children: a and b. I want to create an ``each'' method.
Ideally, I would yield with ``this,'' and then would recurse to ``each''
on every child of that node.
# this doesnt work for so many reasons
class Node
def initialize(me,a,b)
@me = me
@a = a
@b = b
end
def each
# @this represents the calling object (see 1st question)
yield @this
# ideally, the same block would get passed to each of
# these sub calls
@aB.each
@b.each
end
end
Thanks y'all,
--
Nicholas Paul Johnson
nickjohnsonSPAM^H^H^H^[email protected]
http://manjac.ath.cx/nick
_
( ) ascii ribbon campaign - against html mail
X - against microsoft attachments
/ \ http://www.google.com/search?q=ascii+ribbon
--