How to doing a "grep -v" to hide "---" line added by Hash#to_yaml?

Hi, when I convert a Hash to a YAML object and print it a line "---" is added
at the beginning:

···

---------------------------------------------------------

require 'yaml'
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 Castillo

Iñaki Baz Castillo wrote:

Hi, when I convert a Hash to a YAML object and print it a line "---" is
added
at the beginning:

---------------------------------------------------------
> require 'yaml'
> 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]

···

--
Posted via http://www.ruby-forum.com/.

Great :wink:

···

El Domingo, 29 de Junio de 2008, Shashank Agarwal escribió:

Try this

x = {1=>2,"ABC" => {"a"=>"A","b"=>"B"}}.to_yaml
x = x[5...x.length]

--
Iñaki Baz Castillo

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", '')

···

On Jun 29, 2008, at 11:39 AM, Shashank Agarwal wrote:

Try this

x = {1=>2,"ABC" => {"a"=>"A","b"=>"B"}}.to_yaml
x = x[5...x.length]

Stephen Celis 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.

···

--
Posted via http://www.ruby-forum.com/.

Shashank Agarwal 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.

···

--
   Phlip

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.

···

El Domingo, 29 de Junio de 2008, phlip escribió:

Shashank Agarwal 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.

--
Iñaki Baz Castillo

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. (-: