From: Robert Klemme Date: 2013-06-17T23:51:41+09:00 Subject: Re: Issue in reading data from yaml file --089e0149ccded73c4204df5abab0 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Jun 17, 2013 at 4:22 PM, Hassan Schroeder < hassan.schroeder@gmail.com> wrote: > On Mon, Jun 17, 2013 at 4:04 AM, Robert Klemme > wrote: > > >> If you (ahem) read the docs, YAML.load works on strings, not files, > > > > Does it? > > Via the http://ruby-doc.org/stdlib-1.9.3/libdoc/yaml/rdoc/YAML.html > "Usage" example: > > require 'yaml' # STEP ONE, REQUIRE YAML! > # Parse a YAML string > YAML.load("--- foo") #=> "foo" > > Seems straightforward enough :-) > Well, it's just that: an example. To be fair, the documentation is in dire need of improvement. But as you can indeed see from my example (or trying it out yourself) it works not only on YAML strings but also IO objects. > > I'd rather use the form with the IO object because that avoids the > overhead > > of reading the whole file into memory at once. > > The phrase "premature optimization" comes to mind, given the > example under discussion, but whatever floats your boat :-) > Given that the code isn't really that much more complicated I'd barely speak of an optimization - it's more like a habit for me. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --089e0149ccded73c4204df5abab0 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Mon, Jun 17, 2013 at 4:22 PM, Hassan Schroeder <hassan= .schroeder@gmail.com> wrote:
On Mon, Jun 17, 2013 at 4:= 04 AM, Robert Klemme
<shortcutter@googlemail.co= m> wrote:

>> If you (ahem) read the docs, YAML.load works on strings, not files= ,
>
> Does it?

Via the http://ruby-doc.org/stdlib-1.9.3/libdoc/yaml/rdoc/YA= ML.html
"Usage" example:

=A0 require 'yaml' # STEP ONE, REQUIRE YAML!
=A0 # Parse a YAML string
=A0 YAML.load("--- foo") #=3D> "foo"

Seems straightforward enough =A0:-)

Well, it's just that: an example. =A0To be fair, the documentation i= s in dire need of improvement.

But as = you can indeed see from my example (or trying it out yourself) it works not= only on YAML strings but also IO objects.
=A0
> I'd rather use the form with the IO object becau= se that avoids the overhead
> of reading the whole file into memory at once.

The phrase "premature optimization" comes to mind, given th= e
example under discussion, but whatever floats your boat =A0:-)

Given that the code isn'= t really that much more complicated I'd barely speak of an optimization= - it's more like a habit for me.

Cheers

robert
=

--
remember.guy do |as, often| as.you_= can - without end
http://blog.rubybestpractice= s.com/
--089e0149ccded73c4204df5abab0--