Hi, when I convert a Hash to a YAML object and print it a line “—” is
added
at the beginning:
cli> require ‘yaml’
cli> puts({1=>2,“ABC” => {“a”=>“A”,“b”=>“B”}}.to_yaml)
ABC:
a: A
b: B
1: 2
=> nil
Well, how could I hide that annoyin “—” line? Maybe using “grep” in
some
way? other suggestion?
Thanks a lot.
Iñaki Baz C. wrote:
Hi, when I convert a Hash to a YAML object and print it a line “—” is
added
at the beginning:
cli> require ‘yaml’
cli> puts({1=>2,“ABC” => {“a”=>“A”,“b”=>“B”}}.to_yaml)
ABC:
a: A
b: B
1: 2
=> nil
Well, how could I hide that annoyin “—” line? Maybe using “grep” in
some
way? other suggestion?
Thanks a lot.
Try this
x = {1=>2,“ABC” => {“a”=>“A”,“b”=>“B”}}.to_yaml
x = x[5…x.length]
El Domingo, 29 de Junio de 2008, Shashank A. escribió:
Try this
x = {1=>2,“ABC” => {“a”=>“A”,“b”=>“B”}}.to_yaml
x = x[5…x.length]
Great 
On Jun 29, 2008, at 11:39 AM, Shashank A. wrote:
Try this
x = {1=>2,“ABC” => {“a”=>“A”,“b”=>“B”}}.to_yaml
x = x[5…x.length]
Which can be, simply:
{1=>2,“ABC” => {“a”=>“A”,“b”=>“B”}}.to_yaml[5…-1]
It may even be slightly more efficient to use String#sub
{1=>2,“ABC” => {“a”=>“A”,“b”=>“B”}}.to_yaml.sub("— \n", ‘’)
Shashank A. wrote:
{1=>2,“ABC” => {“a”=>“A”,“b”=>“B”}}.to_yaml.sub("— \n", ‘’)
Awesome. Totally forgot about negative indexes.
I would use the .sub option because it is explicit about what it is
removing.
However, the Hash did not add the — . It is part of the YAML standard
as the
start of a document. You should consider leaving it alone, because other
YAML
tools will like it.
El Domingo, 29 de Junio de 2008, phlip escribió:
other YAML tools will like it.
Yes, that’s true, that “—” is part of the YAML grammar, but the fact
is that
I’m only showing it, printing it, no more.
Thanks.
Stephen C. wrote:
Which can be, simply:
{1=>2,“ABC” => {“a”=>“A”,“b”=>“B”}}.to_yaml[5…-1]
It may even be slightly more efficient to use String#sub
{1=>2,“ABC” => {“a”=>“A”,“b”=>“B”}}.to_yaml.sub("— \n", ‘’)
Awesome. Totally forgot about negative indexes.
However, the Hash did not add the — . It is part of the YAML standard as
the start of a document. You should consider leaving it alone, because
other YAML tools will like it.
Yes, that’s true, that “—” is part of the YAML grammar, but the fact is that
I’m only showing it, printing it, no more.
I too have automatically whacked it, for that reason. (-: