Skip to content

Commit 8b1a07b

Browse files
authored
IRB.conf[:SAVE_HISTORY] should handle boolean values (#1062)
Although not documented, `IRB.conf[:SAVE_HISTORY]` used to accept boolean, which now causes `NoMethodError` when used. This commit changes the behavior to accept boolean values and adds tests for the behavior.
1 parent 4d74d39 commit 8b1a07b

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

lib/irb/history.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
module IRB
44
module History
5+
DEFAULT_ENTRY_LIMIT = 1000
6+
57
class << self
68
# Integer representation of <code>IRB.conf[:HISTORY_FILE]</code>.
79
def save_history
10+
return 0 if IRB.conf[:SAVE_HISTORY] == false
11+
return DEFAULT_ENTRY_LIMIT if IRB.conf[:SAVE_HISTORY] == true
812
IRB.conf[:SAVE_HISTORY].to_i
913
end
1014

lib/irb/init.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def IRB.init_config(ap_path)
9393
@CONF[:VERBOSE] = nil
9494

9595
@CONF[:EVAL_HISTORY] = nil
96-
@CONF[:SAVE_HISTORY] = 1000
96+
@CONF[:SAVE_HISTORY] = History::DEFAULT_ENTRY_LIMIT
9797

9898
@CONF[:BACK_TRACE_LIMIT] = 16
9999

test/irb/test_history.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,47 @@ def with_temp_stdio
279279
end
280280

281281
class IRBHistoryIntegrationTest < IntegrationTestCase
282+
def test_history_saving_can_be_disabled_with_false
283+
write_history ""
284+
write_rc <<~RUBY
285+
IRB.conf[:SAVE_HISTORY] = false
286+
RUBY
287+
288+
write_ruby <<~'RUBY'
289+
binding.irb
290+
RUBY
291+
292+
output = run_ruby_file do
293+
type "puts 'foo' + 'bar'"
294+
type "exit"
295+
end
296+
297+
assert_include(output, "foobar")
298+
assert_equal "", @history_file.open.read
299+
end
300+
301+
def test_history_saving_accepts_true
302+
write_history ""
303+
write_rc <<~RUBY
304+
IRB.conf[:SAVE_HISTORY] = true
305+
RUBY
306+
307+
write_ruby <<~'RUBY'
308+
binding.irb
309+
RUBY
310+
311+
output = run_ruby_file do
312+
type "puts 'foo' + 'bar'"
313+
type "exit"
314+
end
315+
316+
assert_include(output, "foobar")
317+
assert_equal <<~HISTORY, @history_file.open.read
318+
puts 'foo' + 'bar'
319+
exit
320+
HISTORY
321+
end
322+
282323
def test_history_saving_with_debug
283324
write_history ""
284325

0 commit comments

Comments
 (0)