Class: IRB::Command::Copy

Inherits:
Base show all
Defined in:
lib/irb/command/copy.rb

Instance Attribute Summary

Attributes inherited from Base

#irb_context

Instance Method Summary collapse

Methods inherited from Base

category, description, execute, help_message, #initialize

Constructor Details

This class inherits a constructor from IRB::Command::Base

Instance Method Details

#execute(arg) ⇒ Object

[View source]

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/irb/command/copy.rb', line 23

def execute(arg)
  # Copy last value if no expression was supplied
  arg = '_' if arg.to_s.strip.empty?

  value = irb_context.workspace.binding.eval(arg)
  output = irb_context.inspect_method.inspect_value(value, +'', colorize: false).chomp

  if clipboard_available?
    copy_to_clipboard(output)
  else
    warn "System clipboard not found"
  end
rescue StandardError => e
  warn "Error: #{e}"
end