Class: IRB::Kit::Handlers::Clipper

Inherits:
Abstract
  • Object
show all
Defined in:
lib/irb/kit/handlers/clipper.rb

Overview

Handles copying content to the macOS clipboard.

Instance Method Summary collapse

Constructor Details

#initialize(processor: IO) ⇒ Clipper

Returns a new instance of Clipper.



8
9
10
11
# File 'lib/irb/kit/handlers/clipper.rb', line 8

def initialize(processor: IO, **)
  @processor = processor
  super(**)
end

Instance Method Details

#call(*lines) ⇒ Object



13
14
15
16
17
18
# File 'lib/irb/kit/handlers/clipper.rb', line 13

def call(*lines)
  processor.popen("pbcopy", "w") { |clipboard| clipboard.write lines.join("\n") }
  io.puts "Copied to clipboard."
rescue Errno::ENOENT
  io.puts "ERROR: Unable to copy since `pbcopy` is only supported on macOS."
end