ruby open pathname with specified encoding -


i trying open files telling ruby 1.9.3 treat them utf-8 encoding.

require 'pathname' pathname.glob("/users/wes/desktop/uf2/*.ics").each { |f|   puts f.read(["encoding:utf-8"]) } 

the class documentation goes through several levels of indirection, not sure specifying encoding properly. when try it, however, error message

ics_scanner_strucdoc.rb:4:in read': can't convert array integer (typeerror) ics_scanner_strucdoc.rb:4:inread' ics_scanner_strucdoc.rb:4:in block in <main>' ics_scanner_strucdoc.rb:3:ineach' ics_scanner_strucdoc.rb:3:in `'

this error message leads me believe read trying interpret open_args optional leading argument, length of read.

if put optional parameters in, in puts f.read(100000, 0, ["encoding:utf-8"]) error message says there many arguments.

what appropriate way specify encoding? correct inconsistency between documentation , behavior of class?

mac os 10.8 rvm current reports "ruby-1.9.3-p484"

i'm not sure want specify encoding path name or file itself.

if latter, maybe want.

pathname.glob("/users/wes/desktop/uf2/*.ics").each { |f|   puts file.open(f,"r:utf-8") } 

with pathname.read can write this.

pathname.glob("/users/wes/desktop/uf2/*.ics").each |f|   path = pathname(f)   puts path.read end 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -