I am trying to get this going where i have this build array and then I
have an array of hashes named after the items in the build. Depending
upon what is in the array, I want to read the arrays of hashes. I wrote
this simple script, but does not work. Any solns
build = [ "log " ,
"top" ]
log = [
{ 'where' => '/home/des/blocks/where.rb'},
{ 'when' => '/home/des/blocks/when.rb'},
{ 'bank' => '/home/des/blocks/bank.rb'}
]
top = [
{ 'where' => '/home/top/blocks/where.rb'},
{ 'when' => '/home/top/blocks/when.rb'},
{ 'bank' => '/home/top/blocks/bank.rb'}
]
build.each{ |bu|
puts bu
bu.each{ |files|
puts files
}}
···
--
Posted via http://www.ruby-forum.com/.
And this code works when I explicitly give the array name
build.each{ |bu|
puts bu
top.each{ |files|
puts files
}}
···
--
Posted via http://www.ruby-forum.com/.
Meta: I'd first suggest that you not build your own build system and look at rake instead.
NonMeta: Instead of splitting everything up and nesting your loops, nest your data structure instead:
build = {
"log" => {
'where' => 'blocks/where.rb',
'when' => 'blocks/when.rb',
'bank' => 'blocks/bank.rb',
},
"top" => {
'where' => 'blocks/where.rb',
'when' => 'blocks/when.rb',
'bank' => 'blocks/bank.rb',
}
}
I didn't see any point in having an array of hashes with single pairs in them, so I took that out too.
Absolute paths in build systems are brittle, use relative paths instead.
···
On Oct 14, 2010, at 14:30 , Veedo Dream wrote:
I am trying to get this going where i have this build array and then I
have an array of hashes named after the items in the build. Depending
upon what is in the array, I want to read the arrays of hashes. I wrote
this simple script, but does not work. Any solns
Er, why would you want to store an array of hashes like that, instead of
just a hash? It would make iterating much easier to use a hash like so:
log = {
'where' => '/path/to/fileA',
'when' => '/path/to/fileB',
'bank' => '/path/to/fileN'
}
#repeat w/ 'top'
build = [log, top]
Then, "build[0]['where'] = '/path/to/fileA'".
Note that, in your implementation, the first array only contains the
strings "log " and "top", and not the hashes, so my last line would
evaluate to nil, not the path.
···
On Thu, 2010-10-14 at 16:30 -0500, Veedo Dream wrote:
I am trying to get this going where i have this build array and then I
have an array of hashes named after the items in the build. Depending
upon what is in the array, I want to read the arrays of hashes. I wrote
this simple script, but does not work. Any solns
build = [ "log " ,
"top" ]
log = [
{ 'where' => '/home/des/blocks/where.rb'},
{ 'when' => '/home/des/blocks/when.rb'},
{ 'bank' => '/home/des/blocks/bank.rb'}
]
top = [
{ 'where' => '/home/top/blocks/where.rb'},
{ 'when' => '/home/top/blocks/when.rb'},
{ 'bank' => '/home/top/blocks/bank.rb'}
]
build.each{ |bu|
puts bu
bu.each{ |files|
puts files
}}
A good idea of using rake, but I have a reason not to use rake and build
my own system. Users here should be able to comment off what they don't
want to built. I know it is crude, but that is the way we want to go.
The reason I have the files located in a different array as I have a lot
many files than 3 to comment off.
Thanks,
···
--
Posted via http://www.ruby-forum.com/.
Maybe I'm missing the point (not quite sure if I got what you want to do),
but how about this?
log = [
{ :where => '/home/des/blocks/where.rb'},
{ :when => '/home/des/blocks/when.rb'},
{ :bank => '/home/des/blocks/bank.rb'}
]
top = [
{ :where => '/home/top/blocks/where.rb'},
{ :when => '/home/top/blocks/when.rb'},
{ :bank => '/home/top/blocks/bank.rb'}
]
build = {:top => top, :log => log}
build.each do |bu|
bu.each do |files|
puts files
end
end
···
On Thu, Oct 14, 2010 at 11:30 PM, Veedo Dream <vikadik@yahoo.com> wrote:
I am trying to get this going where i have this build array and then I
have an array of hashes named after the items in the build. Depending
upon what is in the array, I want to read the arrays of hashes. I wrote
this simple script, but does not work. Any solns
build = [ "log " ,
"top" ]
log = [
\{ 'where' => '/home/des/blocks/where\.rb'\},
\{ 'when' => '/home/des/blocks/when\.rb'\},
\{ 'bank' => '/home/des/blocks/bank\.rb'\}
]
top = [
\{ 'where' => '/home/top/blocks/where\.rb'\},
\{ 'when' => '/home/top/blocks/when\.rb'\},
\{ 'bank' => '/home/top/blocks/bank\.rb'\}
]
build.each{ |bu|
puts bu
bu.each{ |files|
puts files
}}
--
Posted via http://www.ruby-forum.com/\.
---------------------
log
where/home/des/blocks/where.rb
when/home/des/blocks/when.rb
bank/home/des/blocks/bank.rb
top
where/home/top/blocks/where.rb
when/home/top/blocks/when.rb
bank/home/top/blocks/bank.rb
I can't add anything more than has already been said for the direct
question; however, I felt a word of warning is in order.
At the company where I work, we have invented a number of build tools to
help developers streamline their build process and improve build
reliability. As the current maintainer of these tools, I can speak
personally to the fact that unless your organization is in the business
of selling build tools or strongly dedicated the effort for other
reasons, you will most likely saddle those users with overly
complicated, unsupported tools that no one really knows how to use.
That is exactly what has happened for us. Virtually nothing is spent to
properly support these tools or provide decent training and
documentation for their use. As a result, our work is more often
hampered by the tools than helped these days, but it is unbelievably
difficult to claw your way out after you're in, no matter how painful
the home grown tool is to support and use. It's difficult to convince
managers to delay new features and bug fixes so that your team has time
to refactor their code and daily work activities for a new build tool.
I have spoken with other people in the same line of work, and it's the
same story just about every time. If you really need something special,
try to extend an existing tool with as little custom code as possible.
Rake can be quite flexible if you're clever. After all, it's just Ruby
in the end. Writing your own build tool from scratch is almost always a
bad idea.
Just my 2 cents.
-Jeremy
···
On 10/14/2010 4:56 PM, Veedo Dream wrote:
A good idea of using rake, but I have a reason not to use rake and build
my own system. Users here should be able to comment off what they don't
want to built. I know it is crude, but that is the way we want to go.
The reason I have the files located in a different array as I have a lot
many files than 3 to comment off.