On Jan 16, 7:06pm, Josh C. [email protected] wrote:
on each with a regex and for debugging purposes print each lines
That attempt fails because line 21 shows that it’s nil instead the
hash with :n_shares=>$2
, on line 17, but you pull it out with `puts
key to that value. Well, if it gave you that pair, then it is already set.
Hi Josh,
Thanks for your reply. I wrote that stupid stuff late last night and
didn’t like what I was composing. I wrote one approach for
initializing a hash and liked the result well enough, but didn’t like
the copy & paste I did to create it. (I do as much cut and paste as I
can 'cause I hate to feel like a clerk-typist.)
So I had two redundant thing coded. And when I looked at it today, I
forgot what I was doing, so I sent out my SOS.
give yourself a sanity check by breaking it down into as small of steps as
possible.
That’s in keeping with Agile Programming’s principle, and I’m
striving to embrace that. I’m gearing up to actually write my RSpec
stuff first before coding functionality.
I’d think “well, if it isn’t in there, then wtf does my hash look like?” and
instead of
puts h[:shares]
I’d stick a p h
in there.
That’s a great point. I should wean myself off writing so much code
to inspect my code’s result and use Ruby’s inspect in the form of the
‘p’ command. Lesson learned, I hope.
This is my current idea for succinct code to support further data
analysis:
field_names =%w
h = {}
(1…field_names.size).each { |name| h[name] = eval($ + i.to_s) }
Of course, that doesn’t work, but despite my perusing of Pragmatic’s
Programming Ruby, 2nd ed., I haven’t so far figured out how to code
that third line. Any ideas. If you’re too busy, or whatever, don’t
bother responding and I’ll post about it tomorrow.
Many thanks for your thoughtful help.
Best wishes,
Richard