Re: Another Newb asks questions.
- From: Joseph Divelbiss <joseph@xxxxxxxxxx>
- Date: Sun, 1 Jan 2006 00:42:36 +0900
Robert Klemme wrote:
> Daniel Harple <dharple@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>>> require 'enumerator'
>>> $type_hash = type_hash
>>> end
>>> data_files=Dir["#{script_data_dir}*.dat"]
>
> If I'm not mistaken there's a path separator missing. You better use
>
> data_files=Dir[File.join(script_data_dir, "*.dat")]
>
> What do you use the second parameter for? The only reasonable value
> here
> seems to be '*.dat'. Also you're trying to remove the suffix ".dat" and
> reappend it again. Seems a bit strange to me.
>
Yeah I was being silly there. I actually intended to remove the
extension from the filename, thanks for the correction.
>> 1) file.open should be File.open ( actually, you can leave off File
>> too, so it is just open(..). See Kernel#open ).
>> 2) file. basename should be File.basename
>
> Also it's unnecessary since Dir[] always returns basenames *only*.
>
Thank you both. seems that I was misunderstanding how Dir[] worked
exactly. Ill play with that some more.
>> * {} is equivalent to Hash.new
>> * Use { |x| ... } block syntax when the block has only one simple
>> statement (the each_slice part)
>
> Don't use blocks or procs unless you need them (i.e. want to encapsulate
> a
> piece of code and refer it from a variable).
>
I am not exactly sure how you mean by this but I had thought I was doin
it with
"build_hash.call(File.basename(name_of_file))"
> Don't assign a global variable as a side effect from your proc / method
> if
> you also return it. There's especially the problem of your code that
> you
> only get the last hash because all others are lost (the global is
> overwritten all the time).
>
build_hash = Proc.new do |type|
type_hash = Hash.new
...
$type_hash = type_hash
What I had thought this would be doing is to take its input (aka.
Test1.dat or Test2.dat) and make Test1_hash, or Test2_hash and then
convert those to $Test1_hash or $Test2_hash for use elsewhere. am I
experiencing a gross concept error here?
--
Posted via http://www.ruby-forum.com/.
.
- References:
- Another Newb asks questions.
- From: Joseph Divelbiss
- Re: Another Newb asks questions.
- From: Wilson Bilkovich
- Re: Another Newb asks questions.
- From: Joseph Divelbiss
- Re: Another Newb asks questions.
- From: Wilson Bilkovich
- Re: Another Newb asks questions.
- From: Joseph Divelbiss
- Re: Another Newb asks questions.
- From: Matthew Smillie
- Re: Another Newb asks questions.
- From: Joseph Divelbiss
- Re: Another Newb asks questions.
- From: Joseph Divelbiss
- Re: Another Newb asks questions.
- From: Daniel Harple
- Re: Another Newb asks questions.
- From: Robert Klemme
- Another Newb asks questions.
- Prev by Date: Re: Method for turning strings into code
- Next by Date: Re: Is the Ruby executable written in C?
- Previous by thread: Re: Another Newb asks questions.
- Next by thread: Re: Another Newb asks questions.
- Index(es):