From fe2f5dc21b847a8dd7cf470899abed4b14bc5e6c Mon Sep 17 00:00:00 2001 From: Russell Jennings Date: Sat, 7 Dec 2013 07:09:42 -0500 Subject: [PATCH] adds HistoryArray#to_h and spec --- lib/pry/history_array.rb | 5 +++++ spec/history_array_spec.rb | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/pry/history_array.rb b/lib/pry/history_array.rb index 9ffaeea6..9f2635bc 100644 --- a/lib/pry/history_array.rb +++ b/lib/pry/history_array.rb @@ -89,6 +89,11 @@ class Pry ((@count - size)...@count).map { |n| @hash[n] } end + # Returns [Hash] copy of the internal @hash history + def to_h + Marshal.load( Marshal.dump(@hash) ) + end + def pop! @hash.delete @count - 1 @count -= 1 diff --git a/spec/history_array_spec.rb b/spec/history_array_spec.rb index f1bd07aa..041cda4d 100644 --- a/spec/history_array_spec.rb +++ b/spec/history_array_spec.rb @@ -64,4 +64,8 @@ describe Pry::HistoryArray do @populated.pop! @populated.to_a.should == [1, 2, 3] end + + it 'should return an indexed hash' do + @populated.to_h[0].should == @populated[0] + end end