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.com> 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/