How to suppress display of specific code in irb?

I am very new to ruby (but a retired experienced C programmer) and am
getting buried in the amount of documentation available. Have been
unable to find an answer to this question, but perhaps do not understand
the concepts involved enough to search correctly. Given this code

require 'hpricot'
url = "http://www....."
doc = Hpricot.XML(open(url))

In interactive ruby can I suppress the output produced by
   Hpricot.XML(open(url))

is this the stdout stream or is it something else? At completion the
HTML is in the doc object so is there any need for it to also be
displayed. Perhaps the object has a means of suppressing the data being
loaded?

I am working with web pages and a very large amount of data is involved.
When I mark and copy the irb window to a file to do searches on the data
I have a lot of unneeded and duplicated data. Perhaps there are IRB
parameters to resolve this

I know I can redirect to a file then use the file (but still have same
problem when opening file for processing), but what I would like to do
is the equivalent of redirecting stdout (if it is stdout) to NULL on a
per line basis.

Thanks RustySam

···

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

easiest way is:

    Hpricot.XML(open(url)); nil

···

On Oct 3, 2010, at 19:33 , Don Norcott wrote:

In interactive ruby can I suppress the output produced by
  Hpricot.XML(open(url))

What you could do is simply append "; nil" to the end of the line:

irb(main):001:0> s = "some really, really long string" ; nil
=> nil

-Justin

···

On 10/03/2010 07:33 PM, Don Norcott wrote:

I am very new to ruby (but a retired experienced C programmer) and am
getting buried in the amount of documentation available. Have been
unable to find an answer to this question, but perhaps do not understand
the concepts involved enough to search correctly. Given this code

require 'hpricot'
url = "http://www....."
doc = Hpricot.XML(open(url))

In interactive ruby can I suppress the output produced by
    Hpricot.XML(open(url))

is this the stdout stream or is it something else? At completion the
HTML is in the doc object so is there any need for it to also be
displayed. Perhaps the object has a means of suppressing the data being
loaded?

I am working with web pages and a very large amount of data is involved.
When I mark and copy the irb window to a file to do searches on the data
I have a lot of unneeded and duplicated data. Perhaps there are IRB
parameters to resolve this

I know I can redirect to a file then use the file (but still have same
problem when opening file for processing), but what I would like to do
is the equivalent of redirecting stdout (if it is stdout) to NULL on a
per line basis.

Thanks RustySam

You can also add this to your .irbrc:

  def toggle_output
    IRB.conf[:MAIN_CONTEXT].echo = ! IRB.conf[:MAIN_CONTEXT].echo
  end

···

On Oct 3, 2010, at 19:33 , Don Norcott wrote:

In interactive ruby can I suppress the output produced by
  Hpricot.XML(open(url))

Don Norcott wrote:

require 'hpricot'
url = "http://www....."
doc = Hpricot.XML(open(url))

In interactive ruby can I suppress the output produced by
   Hpricot.XML(open(url))

is this the stdout stream or is it something else?

In Ruby, every expression has a value, and by default irb displays that
value (more precisely, it shows value.inspect)

For example:

1+2

=> 3

puts 1+2

3
=> nil

In the second example, "3" is puts producing output, and the return
value from puts is nil.

···

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

You can set the ECHO configuration off:

IRB.conf[:ECHO] = false

HTH,
Ammar

···

On Mon, Oct 4, 2010 at 12:20 PM, Brian Candler <b.candler@pobox.com> wrote:

Don Norcott wrote:

require 'hpricot'
url = "http://www....."
doc = Hpricot.XML(open(url))

In interactive ruby can I suppress the output produced by
Hpricot.XML(open(url))

is this the stdout stream or is it something else?

Thanks these all did the trick. I especially like the toggle.

However even after finding the solution I still could not find where any
of this is documented.

I would like to see an explanation of "string"; null.

I find that adding only a semicolon (no nil)does the trick
doc = Nokogiri::HTML(open(url)); # produces no display

Can you point me to some documentation than may explain the solutions,
so I know where to look next time.

Thanks

···

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

It won't be documented anywhere in the way you're expecting. It's
actually already been explained in these responses.

IRB will print, as the return value, the "last" value of the line you
give it (using inspect), so

1; 2

will return "=> 2" because that's the "last" value of that line.
Adding "; nil" just stops everything before "; nil" from being printed
as output.

···

On Mon, Oct 4, 2010 at 10:55 PM, Don Norcott <dnorcott@mts.net> wrote:

Thanks these all did the trick. I especially like the toggle.

However even after finding the solution I still could not find where any
of this is documented.

I would like to see an explanation of "string"; null.

I find that adding only a semicolon (no nil)does the trick
doc = Nokogiri::HTML(open(url)); # produces no display

Can you point me to some documentation than may explain the solutions,
so I know where to look next time.

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

Thanks these all did the trick. I especially like the toggle.

However even after finding the solution I still could not find where any
of this is documented.

Sure it is. It is documented everywhere. From the pickaxe:

"irb will display the value of each expression as you complete it. For instance: [...irb examples...]"

I would like to see an explanation of "string"; null.

nil, not null.

What more explanation do you want to see, and where? If you have a lot of output from an expression, you augment that expression so that it isn't the final result.

I find that adding only a semicolon (no nil)does the trick
doc = Nokogiri::HTML(open(url)); # produces no display

No, it doesn't. Look at my prompts:

501 % irb
>> "blah"
=> "blah"
>> "blah";
?>

You've told ruby (irb actually) that there is more coming. That's all.

Can you point me to some documentation than may explain the solutions,
so I know where to look next time.

Again. Everywhere. The pickaxe has an entire chapter on the subject.

···

On Oct 4, 2010, at 14:55 , Don Norcott wrote:

Sorry I seem to hit a sore spot. I have no problem with the
answers/explanations given. I have read multiple tutorials but they are
not a good reference source. I have downloaded both core and std
library documentation but it is difficult to retrieve info from as you
must know what your after before you start looking.

I guess I am looking for a non-HTML document that contains the Ruby
spec(like the 'ANSI C Standard' documentation). If such a creature
exists I would appreciated a pointer to it.

I probably did not phrase my original query properly. It had at least
as much to do with finding the documentation that would answer my
questions as opposed to simply looking for an answer.

···

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

Ruby 1.8.7 is not .quite. an ISO standard yet.
It's close to being a Japanese Industrial Standard.

http://ruby-std.netlab.jp/

There is a pdf in amongst these links.

All good!

MarkT

···

I guess I am looking for a non-HTML document that contains the Ruby
spec(like the 'ANSI C Standard' documentation). If such a creature
exists I would appreciated a pointer to it.

--
(+61 4) 0679 5734 :: skype: govirtual.com.au :: チェックアウトが、Jingle だ!
::It's a Jingle Out There!

There is [1], but like the ANSI C standard, it only goes over the core language. I don't think there is an effort to define a specification for the ruby standard library.

[1]: http://www.ipa.go.jp/software/open/ossc/english/ruby/ruby_draft_specification.html

···

On Oct 4, 2010, at 18:53 , Don Norcott wrote:

Sorry I seem to hit a sore spot. I have no problem with the
answers/explanations given. I have read multiple tutorials but they are
not a good reference source. I have downloaded both core and std
library documentation but it is difficult to retrieve info from as you
must know what your after before you start looking.

I guess I am looking for a non-HTML document that contains the Ruby
spec(like the 'ANSI C Standard' documentation). If such a creature
exists I would appreciated a pointer to it.

Don Norcott wrote:

I have read multiple tutorials but they are
not a good reference source. I have downloaded both core and std
library documentation but it is difficult to retrieve info from as you
must know what your after before you start looking.

I learned most from this:
http://ruby-doc.org/docs/ProgrammingRuby/
and I still highly recommend it.

That's the free 1st edition, written for ruby 1.6, but pretty much all
applies to 1.8. I think the book source is floating around somewhere,
and somebody may have made a PDF of it.

Otherwise, it's certainly worth buying the PDF of the 2nd edition. I
would not buy the 3rd edition unless you want to deal with the issues
around ruby 1.9.

···

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

Thanks all, this is exactly what I was looking for.

I had previously read a sample chapter of pragmatic programmer and was
impressed by its clarity. So will go through this book in its entirety.

Thanks again.
Don

···

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