diff options
author | Stan Lo <[email protected]> | 2023-07-03 14:48:19 +0100 |
---|---|---|
committer | git <[email protected]> | 2023-07-03 13:48:23 +0000 |
commit | af9eeb19d8b73a951776ea91901618d6e038d030 (patch) | |
tree | 6636051b3dcff3c71a8ee84dd5df2ce2a6805b48 /lib/irb/context.rb | |
parent | 4430b73cee4aaa4f203e14368d93b3297505c63e (diff) |
[ruby/irb] Stop treating history-saving logic as extension
(https://github.com/ruby/irb/pull/613)
Since `IRB.conf[:SAVE_HISTORY]` is assigned with 1000 by default, history-saving
is a feature enabled by default. So it should not be treated as an extension,
which adds unnecessary complexity to the code.
Diffstat (limited to 'lib/irb/context.rb')
-rw-r--r-- | lib/irb/context.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/irb/context.rb b/lib/irb/context.rb index 6f209b596a..d755622f32 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -8,6 +8,7 @@ require_relative "workspace" require_relative "inspector" require_relative "input-method" require_relative "output-method" +require_relative "history" module IRB # A class that wraps the current state of the irb session, including the @@ -151,6 +152,27 @@ module IRB @command_aliases = IRB.conf[:COMMAND_ALIASES] end + def save_history=(val) + IRB.conf[:SAVE_HISTORY] = val + if val + (IRB.conf[:MAIN_CONTEXT] || self).init_save_history + end + end + + def save_history + IRB.conf[:SAVE_HISTORY] + end + + # A copy of the default <code>IRB.conf[:HISTORY_FILE]</code> + def history_file + IRB.conf[:HISTORY_FILE] + end + + # Set <code>IRB.conf[:HISTORY_FILE]</code> to the given +hist+. + def history_file=(hist) + IRB.conf[:HISTORY_FILE] = hist + end + # The top-level workspace, see WorkSpace#main def main @workspace.main @@ -554,5 +576,11 @@ module IRB command = command_aliases.fetch(command.to_sym, command) ExtendCommandBundle.load_command(command)&.respond_to?(:transform_args) end + + def init_save_history# :nodoc: + unless (class<<@io;self;end).include?(HistorySavingAbility) + @io.extend(HistorySavingAbility) + end + end end end |