Mum's the word (for IRB)

Posted by Rick DeNatale Mon, 12 Mar 2007 14:53:00 GMT

Ara T. Howard posted a nice little IRB hack to ruby-talk about 10 days ago.

I finally got around to incorporating it into my .irbrc file. Here’s my code:

module IRB
  def self.result_format
     conf[:PROMPT][conf[:PROMPT_MODE]][:RETURN]
  end

  def self.result_format=(str)
     result_format.replace(str)
  end

  def self.show_results
     self.result_format = "=> %s\n"
  end

  def self.hide_results
     self.result_format = ''
  end
end

Put this into your .irbc file and you can do this:

rick@frodo:~$ irb
irb(main):001:0> 1+2
=> 3
irb(main):002:0> IRB.result_format
=> "=> %s\n"
irb(main):003:0> IRB.hide_results
irb(main):004:0> 1+2
irb(main):005:0> IRB.show_results
=> "=> %s\n"
irb(main):006:0> 1+2
=> 3

Maybe there are some better names, but it seems to work.

Posted in  | Tags ,  | no comments

Comments

Comments are disabled