It’s a routine from a simple crypto algo, where I’m basically combining
two arrays of data (a “sanitized” stream of data to encrypt, and a
“keystream” to obfuscate the data).
The “pattern” I’m using to combine the streams is a bit ugly, and this
is something I’ve run up against in many other projects as well.
That is, I’m stepping through one array, and then I’m “counting” to keep
track of where I am in the other array, so as to “add” the two arrays.
I know (before calling the routine) that both arrays are of the same
size, and that elements of the corresponding arrays will be added
together.
Is there a way to make this routine prettier? More Ruby-ific?
ruby-1.9.2-p0 > %w( a b c )
=> [“a”, “b”, “c”]
ruby-1.9.2-p0 > %w( a b c ).kind_of?(String)
=> false
ruby-1.9.2-p0 > %w( a b c ).kind_of?(Array)
=> true
irb(main):001:0> RUBY_VERSION
=> “1.8.7”
irb(main):002:0> %w( a b c )
=> [“a”, “b”, “c”]
irb(main):003:0> %w( a b c ).kind_of?(String)
=> false
irb(main):004:0> %w( a b c ).kind_of?(Array)
=> true
ruby-1.9.2-p0 > %w( a b c )
=> [“a”, “b”, “c”]
ruby-1.9.2-p0 > %w( a b c ).kind_of?(String)
=> false
ruby-1.9.2-p0 > %w( a b c ).kind_of?(Array)
=> true
Hi Sam,
Thanks. My mind stopped this the thought that %w creates strings out
of bare words. I forgot that those strings end up in an array. I
should have checked that my stupid claim was correct before posting.
So, with an apology to you and the newsgroup,
I certainly hope I’m not expected to apologise every time I don’t follow
something. The list is, after all, something to learn from.
Thanks, Sam. It’s nice to see a gracious response!
For a while back I received a lot of guff because I wrote and then
posted Ruby code in a style that originated with a big gun at
Microsoft about two decades ago, e.g. sFirstName containing a
reference to a string. Instead of addressing the substance of my
question, they thought it important to hector me for code that lives
quietly and inconspicuously on my computer. It reminded me of Salem,
Mass in the 1600s.
In light of that experience some months ago, your response is a
refreshing indeed.