aboutsummaryrefslogtreecommitdiffstats
path: root/lib/irb
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2023-10-21 19:05:54 +0100
committergit <svn-admin@ruby-lang.org>2023-10-21 18:06:00 +0000
commit745879b5edd385f936bfe086a16fab1f05a4bd15 (patch)
tree27559010452f3b3f6094bf71e354001b9e765aa0 /lib/irb
parent361bce8d2c4c90a01eb3b7365a87dec0d93bb2b6 (diff)
downloadruby-745879b5edd385f936bfe086a16fab1f05a4bd15.tar.gz
[ruby/irb] Minor refactors around irb.rb
(https://github.com/ruby/irb/pull/736) * Remove dead method * Simplify IRB.version * Move private Irb methods together * Centralise @CONF initialization/assignment in init.rb * Move attr_* calls above initialize method https://github.com/ruby/irb/commit/cf23be4395
Diffstat (limited to 'lib/irb')
-rw-r--r--lib/irb/init.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/irb/init.rb b/lib/irb/init.rb
index d1097b5738..d9549420b4 100644
--- a/lib/irb/init.rb
+++ b/lib/irb/init.rb
@@ -5,6 +5,41 @@
#
module IRB # :nodoc:
+ @CONF = {}
+ # Displays current configuration.
+ #
+ # Modifying the configuration is achieved by sending a message to IRB.conf.
+ #
+ # See IRB@Configuration for more information.
+ def IRB.conf
+ @CONF
+ end
+
+ def @CONF.inspect
+ array = []
+ for k, v in sort{|a1, a2| a1[0].id2name <=> a2[0].id2name}
+ case k
+ when :MAIN_CONTEXT, :__TMP__EHV__
+ array.push format("CONF[:%s]=...myself...", k.id2name)
+ when :PROMPT
+ s = v.collect{
+ |kk, vv|
+ ss = vv.collect{|kkk, vvv| ":#{kkk.id2name}=>#{vvv.inspect}"}
+ format(":%s=>{%s}", kk.id2name, ss.join(", "))
+ }
+ array.push format("CONF[:%s]={%s}", k.id2name, s.join(", "))
+ else
+ array.push format("CONF[:%s]=%s", k.id2name, v.inspect)
+ end
+ end
+ array.join("\n")
+ end
+
+ # Returns the current version of IRB, including release version and last
+ # updated date.
+ def IRB.version
+ format("irb %s (%s)", @RELEASE_VERSION, @LAST_UPDATE_DATE)
+ end
# initialize config
def IRB.setup(ap_path, argv: ::ARGV)
@@ -28,6 +63,7 @@ module IRB # :nodoc:
unless ap_path and @CONF[:AP_NAME]
ap_path = File.join(File.dirname(File.dirname(__FILE__)), "irb.rb")
end
+ @CONF[:VERSION] = version
@CONF[:AP_NAME] = File::basename(ap_path, ".rb")
@CONF[:IRB_NAME] = "irb"