.irbrc
ファイルを経由せずに外部環境とデータの受け渡しができるようになります。
def set_clipboard(str)
IO.popen("clip", "w") { |pipe| pipe.print str }
end
alias :orig_set_clipboard :set_clipboard
def get_clipboard
`powershell get-clipboard`
end
class String
def set_clipboard
orig_set_clipboard self
end
end
クリップボードの内容を定数に格納
ヒストリにトークンの内容を残さずに渡せる。
irb> TOKEN = get_clipboard.chomp
=> "PAbOeDPHBWrnLPjQG1rjmJqpBQ2IThLYW685Ev0SYRo="
クリップボードの内容を書き換えてからクリップボードに戻す
変換処理が長くなる場合は一度ローカル変数に格納して処理を複数に分ける。
irb> get_clipboard.gsub("ruby", "RUBY").set_clipboard
=> nil