summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2021-03-18 01:18:42 -0700
committergit <[email protected]>2021-03-21 13:40:21 +0900
commit232433f22423fb6a3ff7a610140c711a964d3b3d (patch)
treefe319dccd48a1b0ea4dbfb0c1939ec37d6809492 /lib
parent5f72962a0955d62dfbac2f7553b725b9d1e9e60d (diff)
[ruby/irb] Add whereami command
https://github.com/ruby/irb/commit/bc822e4aac
Diffstat (limited to 'lib')
-rw-r--r--lib/irb/cmd/whereami.rb20
-rw-r--r--lib/irb/extend-command.rb5
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/irb/cmd/whereami.rb b/lib/irb/cmd/whereami.rb
new file mode 100644
index 0000000000..b3def11b93
--- /dev/null
+++ b/lib/irb/cmd/whereami.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+require_relative "nop"
+
+# :stopdoc:
+module IRB
+ module ExtendCommand
+ class Whereami < Nop
+ def execute(*)
+ code = irb_context.workspace.code_around_binding
+ if code
+ puts code
+ else
+ puts "The current context doesn't have code."
+ end
+ end
+ end
+ end
+end
+# :startdoc:
diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb
index e7b046ad4e..f50068d06c 100644
--- a/lib/irb/extend-command.rb
+++ b/lib/irb/extend-command.rb
@@ -135,6 +135,11 @@ module IRB # :nodoc:
[:measure, NO_OVERRIDE],
],
+ [
+ :irb_whereami, :Whereami, "irb/cmd/whereami",
+ [:whereami, NO_OVERRIDE],
+ ],
+
]
# Installs the default irb commands: