From: Jesús Gabriel y Galán on
On Sun, Apr 4, 2010 at 7:58 PM, Hawksury Gear <blackhawk_932(a)hotmail.com> wrote:
>> Even better
>>
>> require 'pathname'
>> dir = Pathname "K:/test"
>>
>> dir.each_entry do |file|
>>    if file.file?
>>      file.each_line do |line|
>>        ...
>>      end
>>    end
>> end
>>
>> Cheers
>>   robert
>
> Many Thanks Robert, I did the following,
>
> require 'pathname'
>  dir= Pathname "K:/test"
> dir.each_entry do |file|
>  if file.file?
> file.each {|line| print line} ## Checking if it can access a line in a
> file
>  end
>  end
>
> It isn't giving any error message which is great but also not Displaying
> any Output.
> Probably i am not using file.each{|line| print line} correctly.

Try:

file.foreachline {|line| print line}

It seems Pathname objects don't have an each method...

Jesus.

From: Robert Klemme on
On 04.04.2010 19:58, Hawksury Gear wrote:
>> Even better
>>
>> require 'pathname'
>> dir = Pathname "K:/test"
>>
>> dir.each_entry do |file|
>> if file.file?
>> file.each_line do |line|
>> ...
>> end
>> end
>> end
>>
>> Cheers
>> robert
>
> Many Thanks Robert, I did the following,
>
> require 'pathname'
> dir= Pathname "K:/test"
> dir.each_entry do |file|
> if file.file?
> file.each {|line| print line} ## Checking if it can access a line in a
> file
> end
> end
>
> It isn't giving any error message which is great but also not Displaying
> any Output.

Are you sure?

irb(main):004:0> pn.each {|l| p l}
NoMethodError: undefined method `each' for #<Pathname:clnt.rb>
from (irb):4
from /usr/local/bin/irb19:12:in `<main>'



> Probably i am not using file.each{|line| print line} correctly.

I suggest you read my posting again and / or consult documentation.

Regards

robert


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
From: Hawksury Gear on
>> Probably i am not using file.each{|line| print line} correctly.
>
> I suggest you read my posting again and / or consult documentation.
>
> Regards
>
> robert

All works , Thanks very much!
--
Posted via http://www.ruby-forum.com/.

First  |  Prev  | 
Pages: 1 2 3 4 5
Prev: Speeding up TCP
Next: A regexp?