Hi, At Sat, 24 Apr 2004 14:28:45 +0900, Joel VanderWerf wrote in [ruby-talk:98213]: > > $ irb --prompt xmp > > ^^^^^^^^^^^^ > > That's a great feature. It would be nice if the output began with a > comment char '#' so that you could paste into irb (or a source file) and > run. $ grep PROMPT ~/.irbrc IRB.conf[:PROMPT][:XMP][:RETURN] = "# =>%s\n" $ irb --prompt xmp class Hash alias << :update end # =>nil table = Hash.new {{}} # =>{} table["foo"] <<= {"x"=>1} # =>{"x"=>1} table["foo"] <<= {"y"=>2} # =>{"x"=>1, "y"=>2} table # =>{"foo"=>{"x"=>1, "y"=>2}} > > class Hash > > alias << :update > > end > > ==>nil > > table = Hash.new {{}} > > ==>{} > > table["foo"] <<= {"x"=>1} > > ==>{"x"=>1} > > table > > ==>{"foo"=>{"x"=>1}} > > table["bar"] > > Did you mean something like this? > > table["bar"] << {"y"=>2} Just a shorthand for (table["foo"] ||= {})["x"] = 1. -- Nobu Nakada