irbtools 4.0.10 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Irbtools [![[version]](https://badge.fury.io/rb/irbtools.svg)](https://badge.fury.io/rb/irbtools) [![[ci]](https://github.com/janlelis/irbtools/workflows/Test/badge.svg)](https://github.com/janlelis/irbtools/actions?query=workflow%3ATest)
1
+ # Irbtools [![[version]](https://badge.fury.io/rb/irbtools.svg)](https://badge.fury.io/rb/irbtools) [![[ci]](https://github.com/janlelis/irbtools/workflows/Test/badge.svg)](https://github.com/janlelis/irbtools/actions?query=workflow%3ATest)
2
2
 
3
3
  ## Irbtools 4 for Current IRB
4
4
 
@@ -8,12 +8,18 @@ The current version of Irbtools requires [IRB 1.12+](https://github.com/ruby/irb
8
8
 
9
9
  Improves Ruby's IRB with:
10
10
 
11
- - a default configuration
12
- - improved syntax highlighting of result objects
13
- - helpful commands for debugging and introspection
11
+ - a default configuration
12
+ - improved syntax highlighting of result objects
13
+ - helpful commands for debugging and introspection
14
14
 
15
15
  ## Examples
16
16
 
17
+ ### Call system commands with `$`
18
+
19
+ ```ruby
20
+ >> $ git status # displays current git status
21
+ ```
22
+
17
23
  ### Show lookup chain and method list grouped by visibility
18
24
 
19
25
  ```ruby
@@ -145,12 +151,6 @@ require(path)
145
151
  choose_from_list(question, list)
146
152
  ```
147
153
 
148
- ### Call system commands with `$`
149
-
150
- ```ruby
151
- >> $ git status # displays current git status
152
- ```
153
-
154
154
  ## Setup
155
155
 
156
156
  $ gem install irbtools
@@ -169,7 +169,7 @@ your code with:
169
169
 
170
170
  binding.irb
171
171
 
172
- *Optional:* If the **binding_of_caller** gem is available, you can just call the `irb`
172
+ _Optional:_ If the **binding_of_caller** gem is available, you can just call the `irb`
173
173
  method and it will start a session with the current binding:
174
174
 
175
175
  irb
@@ -178,38 +178,38 @@ method and it will start a session with the current binding:
178
178
 
179
179
  ### General IRB Improvements
180
180
 
181
- - Syntax highlighting ([wirb](https://github.com/janlelis/wirb/) / [fancy_irb](https://github.com/janlelis/fancy_irb))
182
- - Loads included libraries efficiently to reduce IRB start-up time
183
- - Customizable views for specfic options using [hirb](https://tagaholic.me/2009/03/13/hirb-irb-on-the-good-stuff.html). By default, ActiveRecord results get displayed as a table.
181
+ - Syntax highlighting ([wirb](https://github.com/janlelis/wirb/) / [fancy_irb](https://github.com/janlelis/fancy_irb))
182
+ - Loads included libraries efficiently to reduce IRB start-up time
183
+ - Customizable views for specfic options using [hirb](https://tagaholic.me/2009/03/13/hirb-irb-on-the-good-stuff.html). By default, ActiveRecord results get displayed as a table.
184
184
 
185
185
  ### Included Debugging Methods for IRB
186
186
 
187
187
  #### Highlights
188
188
 
189
- - Lookup and manipulate instance variables / methods with ease using [object_shadow](https://github.com/janlelis/object_shadow/)
190
- - Go even further with [looksee](https://github.com/oggy/looksee), the best lookup path inspection tool out there
191
- - Display a method's source code using [code](https://github.com/janlelis/code)
192
- - Find methods that turn one value into another value with [methodfinder](https://github.com/citizen428/methodfinder)
193
- - [Use VIM from inside IRB](https://github.com/jberkel/interactive_editor)
189
+ - Lookup and manipulate instance variables / methods with ease using [object_shadow](https://github.com/janlelis/object_shadow/)
190
+ - Go even further with [looksee](https://github.com/oggy/looksee), the best lookup path inspection tool out there
191
+ - Display a method's source code using [code](https://github.com/janlelis/code)
192
+ - Find methods that turn one value into another value with [methodfinder](https://github.com/citizen428/methodfinder)
193
+ - [Use VIM from inside IRB](https://github.com/jberkel/interactive_editor)
194
194
 
195
195
  #### Extra Commands
196
196
 
197
197
  Commands get treated specially by IRB and do not necessarily follow Ruby syntax.
198
198
 
199
- Command | Alias | Description | Example
200
- ------ | ---------- | ---------|---
201
- `code ` | - | Shows syntax-highlighted source code of a method | `code Array#reverse`
202
- `howtocall ` | - | Shows the method signature | `howtocall String#gsub`
203
- `look ` | - | Shows looksee method list | `look [1,2,3]`
204
- `shadow ` | `+ ` | Shows object shadow method list | `shadow [1,2,3]`
205
- `sys ` | `$ ` | Calls system shell | `$ top`
199
+ | Command | Alias | Description | Example |
200
+ | ------------ | ----- | ------------------------------------------------ | ----------------------- |
201
+ | `code ` | - | Shows syntax-highlighted source code of a method | `code Array#reverse` |
202
+ | `howtocall ` | - | Shows the method signature | `howtocall String#gsub` |
203
+ | `look ` | - | Shows looksee method list | `look [1,2,3]` |
204
+ | `shadow ` | `+ ` | Shows object shadow method list | `shadow [1,2,3]` |
205
+ | `sys ` | `$ ` | Calls system shell | `$ top` |
206
206
 
207
207
  Two default commands have an additional alias:
208
208
 
209
- Command | Alias | Description | Example
210
- ------ | ---------- | ---------|---
211
- `show_doc` | `ri ` | Shows documentation | `ri String#gsub`
212
- `chws` | `co ` | "change into an object" | `co [1,2,3]`
209
+ | Command | Alias | Description | Example |
210
+ | ---------- | ----- | ----------------------- | ---------------- |
211
+ | `show_doc` | `ri ` | Shows documentation | `ri String#gsub` |
212
+ | `chws` | `co ` | "change into an object" | `co [1,2,3]` |
213
213
 
214
214
  ##### IRB's ls?
215
215
 
@@ -217,69 +217,69 @@ Please note that IRB's own **ls** command is aliased to `ils`, since `ls` alread
217
217
 
218
218
  #### Ruby Introspection
219
219
 
220
- Method / Constant | Arguments | Description | Provided By
221
- ------ | ---------- | -----------|-
222
- `Object#lp` or `Object#look` | | Supercharged method introspection in IRB | [looksee](https://github.com/oggy/looksee)
223
- `Object#shadow` | | Manipulate instance variables and learn about callable methods | [object_shadow](https://github.com/janlelis/object_shadow/)
224
- `code` | object = self, method_name | Display the method source with syntax highlighting. Will also try to look up C methods. | [code](https://github.com/janlelis/code)
225
- `howtocall` | object = self, method_or_proc | Display parameter names and types you will need to call a method | [debugging/howtocall](https://github.com/janlelis/debugging#howtocallobj--self-method_or_proc)
226
- `mf` | object1, object2 | Find methods which turn one value into another value | [methodfinder](https://github.com/citizen428/methodfinder)
220
+ | Method / Constant | Arguments | Description | Provided By |
221
+ | ---------------------------- | ----------------------------- | --------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
222
+ | `Object#lp` or `Object#look` | | Supercharged method introspection in IRB | [looksee](https://github.com/oggy/looksee) |
223
+ | `Object#shadow` | | Manipulate instance variables and learn about callable methods | [object_shadow](https://github.com/janlelis/object_shadow/) |
224
+ | `code` | object = self, method_name | Display the method source with syntax highlighting. Will also try to look up C methods. | [code](https://github.com/janlelis/code) |
225
+ | `howtocall` | object = self, method_or_proc | Display parameter names and types you will need to call a method | [debugging/howtocall](https://github.com/janlelis/debugging#howtocallobj--self-method_or_proc) |
226
+ | `mf` | object1, object2 | Find methods which turn one value into another value | [methodfinder](https://github.com/citizen428/methodfinder) |
227
227
 
228
228
  #### Platform Info
229
229
 
230
- Method / Constant | Arguments | Description | Provided By
231
- ------ | ---------- | -----------|-
232
- `OS` | | Query operating system information | [os](https://github.com/rdp/os)
233
- `RubyVersion` | | Show the Ruby version | [ruby_version](https://github.com/janlelis/ruby_version)
234
- `RubyEngine` | | Show the Ruby engine | [ruby_engine](https://github.com/janlelis/ruby_engine)
230
+ | Method / Constant | Arguments | Description | Provided By |
231
+ | ----------------- | --------- | ---------------------------------- | -------------------------------------------------------- |
232
+ | `OS` | | Query operating system information | [os](https://github.com/rdp/os) |
233
+ | `RubyVersion` | | Show the Ruby version | [ruby_version](https://github.com/janlelis/ruby_version) |
234
+ | `RubyEngine` | | Show the Ruby engine | [ruby_engine](https://github.com/janlelis/ruby_engine) |
235
235
 
236
236
  #### General Utils
237
237
 
238
- Method / Constant | Arguments | Description | Provided By
239
- ------ | ---------- | -----------|-
240
- `beep` | | Ring terminal bell | [debugging/beep](https://github.com/janlelis/debugging#beep)
241
- `clear` | | Clear the terminal | [every_day_irb](https://github.com/janlelis/every_day_irb)
242
- `copy` | string | Copy something to the clipboard | [clipboard](https://github.com/janlelis/clipboard)
243
- `copy_output` | | Copy session output history to the clipboard | [clipboard](https://github.com/janlelis/clipboard), irbtools
244
- `colorize` | string | Syntax-highlight a string of Ruby code | [coderay](https://github.com/rubychan/coderay), irbtools
245
- `ed` / `emacs` / `mate` / `mvim` / `nano` / `vi` / `vim` | filename = nil | Start an editor in the session context | [interactive_editor](https://github.com/jberkel/interactive_editor)
246
- `ld` | file | Shortcut for `load lib.to_s + '.rb'` | [every_day_irb](https://github.com/janlelis/every_day_irb)
247
- `pa` | string, color | Print a string in the specified color | [paint](https://github.com/janlelis/paint#utilities)
248
- `page` | what, options = {} | Use pager to improve viewing longer content | [hirb](https://github.com/cldwalker/hirb#pager), irbtools
249
- `paste` | | Paste clipboard content | [clipboard](https://github.com/janlelis/clipboard)
250
- `q` | *args | Like `Kernel#p`, but prints results on one line, with different colors | [debugging/q](https://github.com/janlelis/debugging#qargs)
251
- `re` | string, regexg, groups = nil | Regex debugging helper | [debugging/re](https://github.com/janlelis/debugging#qargs)
252
- `reset!` | | Restart the current IRB session | [every_day_irb](https://github.com/janlelis/every_day_irb)
253
- `rq` | lib | Shortcut for `require lib.to_s`. Use it like this: `rq:prime` | [every_day_irb](https://github.com/janlelis/every_day_irb)
254
- `rr` | lib | Shortcut for `require_relative lib.to_s` | [every_day_irb](https://github.com/janlelis/every_day_irb)
255
- `rrq` / `rerequire` | lib | Hack to remove a library from `$LOADED_FEATURES` and `require` it again | [every_day_irb](https://github.com/janlelis/every_day_irb)
256
- `wp` | inspect_string | Syntax-highlight a Ruby return value | [wirb](https://github.com/janlelis/wirb#kernelwp)
238
+ | Method / Constant | Arguments | Description | Provided By |
239
+ | -------------------------------------------------------- | ---------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------- |
240
+ | `beep` | | Ring terminal bell | [debugging/beep](https://github.com/janlelis/debugging#beep) |
241
+ | `clear` | | Clear the terminal | [every_day_irb](https://github.com/janlelis/every_day_irb) |
242
+ | `copy` | string | Copy something to the clipboard | [clipboard](https://github.com/janlelis/clipboard) |
243
+ | `copy_output` | | Copy session output history to the clipboard | [clipboard](https://github.com/janlelis/clipboard), irbtools |
244
+ | `colorize` | string | Syntax-highlight a string of Ruby code | [coderay](https://github.com/rubychan/coderay), irbtools |
245
+ | `ed` / `emacs` / `mate` / `mvim` / `nano` / `vi` / `vim` | filename = nil | Start an editor in the session context | [interactive_editor](https://github.com/jberkel/interactive_editor) |
246
+ | `ld` | file | Shortcut for `load lib.to_s + '.rb'` | [every_day_irb](https://github.com/janlelis/every_day_irb) |
247
+ | `pa` | string, color | Print a string in the specified color | [paint](https://github.com/janlelis/paint#utilities) |
248
+ | `page` | what, options = {} | Use pager to improve viewing longer content | [hirb](https://github.com/cldwalker/hirb#pager), irbtools |
249
+ | `paste` | | Paste clipboard content | [clipboard](https://github.com/janlelis/clipboard) |
250
+ | `q` | \*args | Like `Kernel#p`, but prints results on one line, with different colors | [debugging/q](https://github.com/janlelis/debugging#qargs) |
251
+ | `re` | string, regexg, groups = nil | Regex debugging helper | [debugging/re](https://github.com/janlelis/debugging#qargs) |
252
+ | `reset!` | | Restart the current IRB session | [every_day_irb](https://github.com/janlelis/every_day_irb) |
253
+ | `rq` | lib | Shortcut for `require lib.to_s`. Use it like this: `rq:prime` | [every_day_irb](https://github.com/janlelis/every_day_irb) |
254
+ | `rr` | lib | Shortcut for `require_relative lib.to_s` | [every_day_irb](https://github.com/janlelis/every_day_irb) |
255
+ | `rrq` / `rerequire` | lib | Hack to remove a library from `$LOADED_FEATURES` and `require` it again | [every_day_irb](https://github.com/janlelis/every_day_irb) |
256
+ | `wp` | inspect_string | Syntax-highlight a Ruby return value | [wirb](https://github.com/janlelis/wirb#kernelwp) |
257
257
 
258
258
  #### Files and Navigation
259
259
 
260
- Method / Constant | Arguments | Description | Provided By
261
- ------ | ---------- | -----------|-
262
- `cat` | path | Read file contents | [every_day_irb](https://github.com/janlelis/every_day_irb)
263
- `cd` | path = nil | Change the directory. Can also be used in these forms: `~cd` (change to home directory), `-cd` (change to previous directory) | [cd](https://github.com/janlelis/cd)
264
- `chmod` | mode, path | Set file mode for file | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
265
- `chmod_R` | mode, path | Set file mode for directory | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
266
- `chown` | user, group, path | Set file owner for file | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
267
- `chown_R` | user, group, path | Set file owner for directory | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
268
- `cp` | source, destination | Copy file | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
269
- `cp_r` | source, destination | Copy directory | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
270
- `ls` | path = "." | List directory content | [cd](https://github.com/janlelis/cd)
271
- `ln` | target, link | Create symlink (`ln`) | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
272
- `ln_s` | target, link | Create symlink (`ln -s`) | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
273
- `ln_sf` | target, link | Create symlink (`ln -sf`) | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
274
- `mkdir` | path | Create a new directory | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
275
- `mkdir_p` | path | Create a new directory (with `-p` option) | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
276
- `cp` | source, destination | Move file or directory | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
277
- `pwd` | | Return current directory | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
278
- `ray` | path | Syntax highlight a Ruby file | [coderay](https://github.com/rubychan/coderay), irbtools
279
- `rm` | path | Delete a file (`rm`) | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
280
- `rm_r` | path | Delete a file or directory (`rm -r`) | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
281
- `rm_rf` | path | Delete a file or directory, with force (`rm -rf`) | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
282
- `rmdir` | path | Delete an empty directory | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html)
260
+ | Method / Constant | Arguments | Description | Provided By |
261
+ | ----------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
262
+ | `cat` | path | Read file contents | [every_day_irb](https://github.com/janlelis/every_day_irb) |
263
+ | `cd` | path = nil | Change the directory. Can also be used in these forms: `~cd` (change to home directory), `-cd` (change to previous directory) | [cd](https://github.com/janlelis/cd) |
264
+ | `chmod` | mode, path | Set file mode for file | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
265
+ | `chmod_R` | mode, path | Set file mode for directory | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
266
+ | `chown` | user, group, path | Set file owner for file | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
267
+ | `chown_R` | user, group, path | Set file owner for directory | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
268
+ | `cp` | source, destination | Copy file | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
269
+ | `cp_r` | source, destination | Copy directory | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
270
+ | `ls` | path = "." | List directory content | [cd](https://github.com/janlelis/cd) |
271
+ | `ln` | target, link | Create symlink (`ln`) | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
272
+ | `ln_s` | target, link | Create symlink (`ln -s`) | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
273
+ | `ln_sf` | target, link | Create symlink (`ln -sf`) | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
274
+ | `mkdir` | path | Create a new directory | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
275
+ | `mkdir_p` | path | Create a new directory (with `-p` option) | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
276
+ | `cp` | source, destination | Move file or directory | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
277
+ | `pwd` | | Return current directory | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
278
+ | `ray` | path | Syntax highlight a Ruby file | [coderay](https://github.com/rubychan/coderay), irbtools |
279
+ | `rm` | path | Delete a file (`rm`) | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
280
+ | `rm_r` | path | Delete a file or directory (`rm -r`) | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
281
+ | `rm_rf` | path | Delete a file or directory, with force (`rm -rf`) | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
282
+ | `rmdir` | path | Delete an empty directory | [fileutils](https://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/FileUtils.html) |
283
283
 
284
284
  ### Advanced Tweaking
285
285
 
@@ -312,7 +312,8 @@ You can use **Irbtools** without colors/IRB extensions. To do so, put this into
312
312
  require 'irbtools/non_fancy'
313
313
  Irbtools.start
314
314
  ```
315
- ## J-_-L
316
315
 
317
- Copyright (c) 2010-2023 Jan Lelis <https://janlelis.com> released under the MIT
316
+ ## J-\_-L
317
+
318
+ Copyright (c) 2010-2024 Jan Lelis <https://janlelis.com> released under the MIT
318
319
  license.
data/irbtools.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  # Dependencies
21
21
 
22
22
  # Core Functionality
23
- s.add_dependency %q<irb>, ">= 1.12.0", "< 1.14"
23
+ s.add_dependency %q<irb>, ">= 1.13.0", "< 1.15"
24
24
  s.add_dependency %q<every_day_irb>, "~> 2.2"
25
25
  s.add_dependency %q<fancy_irb>, "~> 2.1"
26
26
  s.add_dependency %q<wirb>, "~> 2.0", ">= 2.2.1"
@@ -1,31 +1,44 @@
1
- require "irb/command/base"
1
+ require "irb/command"
2
2
 
3
- module IRB
3
+ module Irbtools
4
4
  module Command
5
- class Code < Base
5
+ class Code < IRB::Command::Base
6
6
  category "Introspection"
7
7
  description "Shows the syntax-highlighted source code of a method"
8
+ help_message <<~HELP
9
+ Shows the syntax-highlighted source code of a method. Works with Ruby's
10
+ native methods.
8
11
 
9
- class << self
10
- def transform_args(args)
11
- if args.strip =~ /\A(?:([\w:]+)([#.]))?(\w+[?!]?)\z/
12
- if $1
13
- if $2 == "#"
14
- "#{$1}, #{$1}.instance_method(:#{$3})"
15
- else
16
- "#{$1}, :#{$3}"
17
- end
12
+ Example usages:
13
+ >> code SecureRandom.uuid
14
+ >> code Array#reverse
15
+ HELP
16
+
17
+ def transform_arg(arg)
18
+ if arg.empty?
19
+ "[]"
20
+ elsif arg.strip =~ /\A(?:([\w:]+)([#.]))?(\w+[?!]?)\z/
21
+ if $1
22
+ if $2 == "#"
23
+ "[#{$1}, #{$1}.instance_method(:#{$3})]"
18
24
  else
19
- ":" + $3
25
+ "[#{$1}, :#{$3}]"
20
26
  end
21
27
  else
22
- args
28
+ "[:#{$3}]"
23
29
  end
30
+ else
31
+ nil
24
32
  end
25
33
  end
26
34
 
27
- def execute(*args)
28
- @irb_context.workspace.binding.send(:code, *args)
35
+ def execute(arg)
36
+ if code_parameters_code = transform_arg(arg)
37
+ code_parameters = @irb_context.workspace.binding.eval(code_parameters_code)
38
+ @irb_context.workspace.binding.send(:code, *code_parameters)
39
+ else
40
+ warn "code: Please use rdoc syntax, e.g. Array#sum"
41
+ end
29
42
  rescue NameError
30
43
  warn "code: Class or method not found."
31
44
  end
@@ -1,31 +1,44 @@
1
- require "irb/command/base"
1
+ require "irb/command"
2
2
 
3
- module IRB
3
+ module Irbtools
4
4
  module Command
5
- class Howtocall < Base
5
+ class Howtocall < IRB::Command::Base
6
6
  category "Introspection"
7
7
  description "Displays method signatures based on Method#parameters"
8
+ help_message <<~HELP
9
+ Displays method signatures based on Method#parameters, with the same limitations,
10
+ so it's more useful with methods implemented in Ruby itself
8
11
 
9
- class << self
10
- def transform_args(args)
11
- if args.strip =~ /\A(?:([\w:]+)([#.]))?(\w+[?!]?)\z/
12
- if $1
13
- if $2 == "#"
14
- "#{$1}, #{$1}.instance_method(:#{$3})"
15
- else
16
- "#{$1}, :#{$3}"
17
- end
12
+ Example usages:
13
+ >> howtocall Gem.add_to_load_path
14
+ >> howtocall Array#sum
15
+ HELP
16
+
17
+ def transform_arg(arg)
18
+ if arg.empty?
19
+ "[]"
20
+ elsif arg.strip =~ /\A(?:([\w:]+)([#.]))?(\w+[?!]?)\z/
21
+ if $1
22
+ if $2 == "#"
23
+ "[#{$1}, #{$1}.instance_method(:#{$3})]"
18
24
  else
19
- ":" + $3
25
+ "[#{$1}, :#{$3}]"
20
26
  end
21
27
  else
22
- args
28
+ "[:#{$3}]"
23
29
  end
30
+ else
31
+ nil
24
32
  end
25
33
  end
26
34
 
27
- def execute(*args)
28
- @irb_context.workspace.binding.send(:howtocall, *args)
35
+ def execute(arg)
36
+ if howtocall_parameters_code = transform_arg(arg)
37
+ howtocall_parameters = @irb_context.workspace.binding.eval(howtocall_parameters_code)
38
+ @irb_context.workspace.binding.send(:howtocall, *howtocall_parameters)
39
+ else
40
+ warn "howtocall: Please use rdoc syntax, e.g. Array#sum"
41
+ end
29
42
  rescue NameError
30
43
  warn "howtocall: Class or method not found"
31
44
  end
@@ -1,20 +1,23 @@
1
- require "irb/command/base"
1
+ require "irb/command"
2
2
 
3
- module IRB
3
+ module Irbtools
4
4
  module Command
5
- class Look < Base
5
+ class Look < IRB::Command::Base
6
6
  category "Introspection"
7
- description 'Method list and lookup path inspection based on looksee gem'
7
+ description 'Method list and lookup path inspection based on the looksee gem'
8
+ help_message <<~HELP
9
+ Method list and lookup path inspection based on the looksee gem.
8
10
 
9
- def execute(*args)
10
- if args.empty?
11
- @irb_context.workspace.binding.look
11
+ Example usage: look [1,2,3]
12
+ HELP
13
+
14
+ def execute(arg)
15
+ if arg.strip.empty?
16
+ p @irb_context.workspace.binding.look
12
17
  else
13
- obj, *params = *args
14
- obj.look(*params)
18
+ p @irb_context.workspace.binding.eval(arg).look
15
19
  end
16
20
  end
17
21
  end
18
22
  end
19
23
  end
20
-
@@ -1,17 +1,21 @@
1
- require "irb/command/base"
1
+ require "irb/command"
2
2
 
3
- module IRB
3
+ module Irbtools
4
4
  module Command
5
- class Shadow < Base
5
+ class Shadow < IRB::Command::Base
6
6
  category "Introspection"
7
- description 'Method list and lookup path inspection based on object shadow gem'
7
+ description 'Method list and lookup path inspection based on the object shadow gem'
8
+ help_message <<~HELP
9
+ Method list and lookup path inspection based on the object shadow gem.
8
10
 
9
- def execute(*args)
10
- if args.empty?
11
- @irb_context.workspace.binding.shadow
11
+ Example usage: + [1,2,3]
12
+ HELP
13
+
14
+ def execute(arg)
15
+ if arg.strip.empty?
16
+ p @irb_context.workspace.binding.shadow
12
17
  else
13
- obj, *params = *args
14
- obj.shadow(*params)
18
+ p @irb_context.workspace.binding.eval(arg).shadow
15
19
  end
16
20
  end
17
21
  end
@@ -1,23 +1,18 @@
1
- require "irb/command/base"
1
+ require "irb/command"
2
2
 
3
- module IRB
3
+ module Irbtools
4
4
  module Command
5
- class Sys < Base
5
+ class Sys < IRB::Command::Base
6
6
  category "Misc"
7
7
  description 'Run a system command'
8
+ help_message <<~HELP
9
+ Run a command via Ruby's Kernel#system method
8
10
 
9
- class << self
10
- def transform_args(args)
11
- if args.empty? || string_literal?(args)
12
- args
13
- else
14
- args.strip.dump
15
- end
16
- end
17
- end
11
+ Example usage: $ cowsay "Hello from IRB"
12
+ HELP
18
13
 
19
- def execute(*args)
20
- system(*args)
14
+ def execute(arg)
15
+ system(arg)
21
16
  end
22
17
  end
23
18
  end
@@ -1,4 +1,5 @@
1
1
  require_relative 'version'
2
2
 
3
3
  require_relative 'implementation'
4
+ require_relative "commands"
4
5
  require_relative 'libraries' unless Irbtools.minimal
@@ -127,18 +127,11 @@ module Irbtools
127
127
  end
128
128
 
129
129
  def load_commands
130
- ec = IRB::ExtendCommandBundle.instance_variable_get(:@EXTEND_COMMANDS)
131
-
132
- [
133
- [:code, :Code, nil, [:code, IRB::ExtendCommandBundle::OVERRIDE_ALL]],
134
- [:howtocall, :Howtocall, nil, [:howtocall, IRB::ExtendCommandBundle::OVERRIDE_ALL]],
135
- [:look, :Look, nil, [:look, IRB::ExtendCommandBundle::OVERRIDE_ALL]],
136
- [:shadow, :Shadow, nil, [:shadow, IRB::ExtendCommandBundle::OVERRIDE_ALL]],
137
- [:sys, :Sys, nil, [:sys, IRB::ExtendCommandBundle::OVERRIDE_ALL]],
138
- ].each{ |ecconfig|
139
- ec.push(ecconfig)
140
- IRB::ExtendCommandBundle.def_extend_command(*ecconfig)
141
- }
130
+ IRB::Command.register(:code, Irbtools::Command::Code)
131
+ IRB::Command.register(:howtocall, Irbtools::Command::Howtocall)
132
+ IRB::Command.register(:look, Irbtools::Command::Look)
133
+ IRB::Command.register(:shadow, Irbtools::Command::Shadow)
134
+ IRB::Command.register(:sys, Irbtools::Command::Sys)
142
135
  end
143
136
 
144
137
  def add_command_aliases
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Irbtools
4
- VERSION = "4.0.10"
4
+ VERSION = "4.1.0"
5
5
  end
data/lib/irbtools.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require_relative "irbtools/configure"
2
- require_relative "irbtools/commands"
3
2
 
4
3
  require "irb"
5
4
 
@@ -5,18 +5,18 @@ describe "irbtools commands" do
5
5
  describe "howtocall / code" do
6
6
  it "support ri Syntax like String.name or String#gsub" do
7
7
  expect(
8
- IRB::Command::Howtocall.transform_args("String.name")
9
- ).to eq "String, :name"
8
+ Irbtools::Command::Howtocall.new(nil).transform_arg("String.name")
9
+ ).to eq "[String, :name]"
10
10
 
11
11
  expect(
12
- IRB::Command::Code.transform_args("String#gsub")
13
- ).to eq "String, String.instance_method(:gsub)"
12
+ Irbtools::Command::Code.new(nil).transform_arg("String#gsub")
13
+ ).to eq "[String, String.instance_method(:gsub)]"
14
14
  end
15
15
 
16
16
  it "supports question-mark methods" do
17
17
  expect(
18
- IRB::Command::Howtocall.transform_args("String#ascii_only?")
19
- ).to eq "String, String.instance_method(:ascii_only?)"
18
+ Irbtools::Command::Howtocall.new(nil).transform_arg("String#ascii_only?")
19
+ ).to eq "[String, String.instance_method(:ascii_only?)]"
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irbtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.10
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Lelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-03 00:00:00.000000000 Z
11
+ date: 2024-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: irb
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.12.0
19
+ version: 1.13.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '1.14'
22
+ version: '1.15'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 1.12.0
29
+ version: 1.13.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '1.14'
32
+ version: '1.15'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: every_day_irb
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -325,6 +325,7 @@ extra_rdoc_files: []
325
325
  files:
326
326
  - ".editorconfig"
327
327
  - ".gitignore"
328
+ - ".rake_tasks"
328
329
  - CHANGELOG-MORE.md
329
330
  - CHANGELOG.md
330
331
  - CODE_OF_CONDUCT.md
@@ -375,7 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
375
376
  - !ruby/object:Gem::Version
376
377
  version: '0'
377
378
  requirements: []
378
- rubygems_version: 3.5.9
379
+ rubygems_version: 3.5.20
379
380
  signing_key:
380
381
  specification_version: 4
381
382
  summary: Irbtools happy IRB.