summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2018-10-19 22:03:41 +0800
committerKyrylo Silin <silin@kyrylo.org>2018-10-20 00:36:22 +0800
commit2519818cc9a1b274f6f6ad686258ac2969b0f5c4 (patch)
treebace8ff42455307928283e8ad25c9c2cd2d221e4
parentd37d0c0489f52659238a04ec3e9e7906999d1269 (diff)
downloadpry-2519818cc9a1b274f6f6ad686258ac2969b0f5c4.tar.gz
Rename HistoryArray to Ring
`HistoryArray` is a very specific name and it doesn't tell the reader what it *really* means unless you read its code or the docs of the class. On the other hand, `Ring` is a [very well-known term][1], which means exactly what `HistoryArray` does. The alias name for it is circular buffer. I chose `Ring` because it is shorter and used by Golang, so I expect programmers to be familiar with `Ring`. [1]: https://en.wikipedia.org/wiki/Circular_buffer
-rw-r--r--lib/pry.rb2
-rw-r--r--lib/pry/pry_instance.rb8
-rw-r--r--lib/pry/ring.rb (renamed from lib/pry/history_array.rb)24
-rw-r--r--spec/pry_spec.rb4
-rw-r--r--spec/ring_spec.rb (renamed from spec/history_array_spec.rb)20
5 files changed, 29 insertions, 29 deletions
diff --git a/lib/pry.rb b/lib/pry.rb
index ccf0af6c..1faad7be 100644
--- a/lib/pry.rb
+++ b/lib/pry.rb
@@ -144,7 +144,7 @@ require 'pathname'
require 'pry/version'
require 'pry/repl'
require 'pry/code'
-require 'pry/history_array'
+require 'pry/ring'
require 'pry/helpers'
require 'pry/code_object'
require 'pry/method'
diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb
index 16b4ec99..32901f7c 100644
--- a/lib/pry/pry_instance.rb
+++ b/lib/pry/pry_instance.rb
@@ -72,8 +72,8 @@ class Pry
@config = Pry::Config.new
config.merge!(options)
push_prompt(config.prompt)
- @input_array = Pry::HistoryArray.new config.memory_size
- @output_array = Pry::HistoryArray.new config.memory_size
+ @input_array = Pry::Ring.new(config.memory_size)
+ @output_array = Pry::Ring.new(config.memory_size)
@custom_completions = config.command_completions
set_last_result nil
@input_array << nil
@@ -177,8 +177,8 @@ class Pry
undef :memory_size= if method_defined? :memory_size=
def memory_size=(size)
- @input_array = Pry::HistoryArray.new(size)
- @output_array = Pry::HistoryArray.new(size)
+ @input_array = Pry::Ring.new(size)
+ @output_array = Pry::Ring.new(size)
end
# Inject all the sticky locals into the current binding.
diff --git a/lib/pry/history_array.rb b/lib/pry/ring.rb
index ad476011..4980cb3c 100644
--- a/lib/pry/history_array.rb
+++ b/lib/pry/ring.rb
@@ -1,19 +1,19 @@
class Pry
- # A history array is an array to which you can only add elements. Older
- # entries are removed progressively, so that the array never contains more than
- # N elements.
+ # A ring is an array to which you can only add elements. Older entries are
+ # removed progressively, so that the array never contains more than N
+ # elements.
#
- # History arrays are used by Pry to store the output of the last commands.
+ # Rings are used by Pry to store the output of the last commands.
#
# @example
- # ary = Pry::HistoryArray.new 10
- # ary << 1 << 2 << 3
- # ary[0] # => 1
- # ary[1] # => 2
- # 10.times { |n| ary << n }
- # ary[0] # => nil
- # ary[-1] # => 9
- class HistoryArray
+ # ring = Pry::Ring.new(10)
+ # ring << 1 << 2 << 3
+ # ring[0] # => 1
+ # ring[1] # => 2
+ # 10.times { |n| ring << n }
+ # ring[0] # => nil
+ # ring[-1] # => 9
+ class Ring
include Enumerable
# @param [Integer] size Maximum amount of objects in the array
diff --git a/spec/pry_spec.rb b/spec/pry_spec.rb
index a727ae52..3be96b06 100644
--- a/spec/pry_spec.rb
+++ b/spec/pry_spec.rb
@@ -273,7 +273,7 @@ describe Pry do
t.eval "42"
res = t.eval "_out_"
- expect(res).to be_a_kind_of Pry::HistoryArray
+ expect(res).to be_a_kind_of(Pry::Ring)
expect(res[1..2]).to eq [:foo, 42]
end
@@ -283,7 +283,7 @@ describe Pry do
t.eval "42"
res = t.eval "_in_"
- expect(res).to be_a_kind_of Pry::HistoryArray
+ expect(res).to be_a_kind_of(Pry::Ring)
expect(res[1..2]).to eq [":foo\n", "42\n"]
end
diff --git a/spec/history_array_spec.rb b/spec/ring_spec.rb
index 2d7d7b8b..65630d12 100644
--- a/spec/history_array_spec.rb
+++ b/spec/ring_spec.rb
@@ -1,13 +1,13 @@
require_relative 'helper'
-describe Pry::HistoryArray do
+describe Pry::Ring do
before do
- @array = Pry::HistoryArray.new 10
- @populated = @array.dup << 1 << 2 << 3 << 4
+ @ring = Pry::Ring.new(10)
+ @populated = @ring.dup << 1 << 2 << 3 << 4
end
it 'should have a maximum size specifed at creation time' do
- expect(@array.max_size).to eq 10
+ expect(@ring.max_size).to eq 10
end
it 'should be able to be added objects to' do
@@ -48,16 +48,16 @@ describe Pry::HistoryArray do
end
it 'should remove older entries' do
- 11.times { |n| @array << n }
+ 11.times { |n| @ring << n }
- expect(@array[0]).to eq nil
- expect(@array[1]).to eq 1
- expect(@array[10]).to eq 10
+ expect(@ring[0]).to eq nil
+ expect(@ring[1]).to eq 1
+ expect(@ring[10]).to eq 10
end
it 'should not be larger than specified maximum size' do
- 12.times { |n| @array << n }
- expect(@array.entries.compact.size).to eq 10
+ 12.times { |n| @ring << n }
+ expect(@ring.entries.compact.size).to eq 10
end
it 'should pop!' do