「Ruby を実行」の版間の差分
ナビゲーションに移動
検索に移動
編集の要約なし |
編集の要約なし |
||
| 34行目: | 34行目: | ||
'def self.r(*s) s.each {|x| require x.to_s } end;' + | 'def self.r(*s) s.each {|x| require x.to_s } end;' + | ||
'def self.e(str, enc=nil) URI.encode_www_form_component(str.to_s, enc) end;' + | 'def self.e(str, enc=nil) URI.encode_www_form_component(str.to_s, enc).tr(?+, %_ _) end;' + | ||
'$0 = URI.decode_www_form_component(STDIN.gets.rstrip);' + | '$0 = URI.decode_www_form_component(STDIN.gets.rstrip);' + | ||
| 43行目: | 43行目: | ||
'begin;' + | 'begin;' + | ||
'print Timeout.timeout(2) { e(eval($_) | 'print Timeout.timeout(2) { e(eval($_)) };' + | ||
'rescue Exception => e;' + | 'rescue Exception => e;' + | ||
'print e(%_#<#{e.full_message}> | 'print e(%_#<#{e.full_message}>_);' + | ||
'end' + | 'end' + | ||
'"') | '"') | ||
| 78行目: | 78行目: | ||
'def self.r(*s) s.each {|x| require x.to_s } end;' + | 'def self.r(*s) s.each {|x| require x.to_s } end;' + | ||
'def self.e(str, enc=nil) URI.encode_www_form_component(str.to_s, enc) end;' + | 'def self.e(str, enc=nil) URI.encode_www_form_component(str.to_s, enc).tr(?+, %_ _) end;' + | ||
'$0 = URI.decode_www_form_component(STDIN.gets.rstrip);' + | '$0 = URI.decode_www_form_component(STDIN.gets.rstrip);' + | ||
| 87行目: | 87行目: | ||
'begin;' + | 'begin;' + | ||
'print Timeout.timeout(2) { e(eval($_) | 'print Timeout.timeout(2) { e(eval($_)) };' + | ||
'rescue Exception => e;' + | 'rescue Exception => e;' + | ||
'print e(%_#<#{e.full_message}> | 'print e(%_#<#{e.full_message}>_);' + | ||
'end' + | 'end' + | ||
'"') | '"') | ||
2020年4月11日 (土) 00:22時点における版
選択範囲をRubyでevalして結果をその場に出します。Ruby本体( https://github.com/oneclick/rubyinstaller2/releases )が必要です。
以下のショートカット用の変数とメソッドを定義しています。
r(シンボル, シンボル, シンボル...)- 引数を
require e(文字列)- 引数をURIエンコード (文字化け対策。出力には
decodeURIComponentをかませています) $_- eval中のテキスト
$_.rest- eval中のテキストのうち、
__END__以降
置き換え版
// Rubyを実行 (置き換え版).js
// rubyw.exe の場所を指定
var RUBY_PATH = 'C:\\Program Files\\rubyinstaller-2.7.1-1-x64\\bin\\rubyw.exe'
if (document.selection.IsEmpty) {
document.selection.EndOfLine(false, mePosLogical)
document.selection.StartOfLine(true, mePosLogical)
}
var shell = new ActiveXObject('WScript.Shell')
shell.CurrentDirectory = document.Path || shell.SpecialFolders("Desktop")
var exec = shell.Exec(
'"' + RUBY_PATH + '"' +
' -ruri/common -rtimeout' +
' -e "' +
'STDERR.reopen STDOUT;' +
'def self.r(*s) s.each {|x| require x.to_s } end;' +
'def self.e(str, enc=nil) URI.encode_www_form_component(str.to_s, enc).tr(?+, %_ _) end;' +
'$0 = URI.decode_www_form_component(STDIN.gets.rstrip);' +
'$_ = URI.decode_www_form_component(STDIN.read);' +
'def $_.rest;' +
'self =~ /^__END__/ and $\'[1..-1];' +
'end;' +
'begin;' +
'print Timeout.timeout(2) { e(eval($_)) };' +
'rescue Exception => e;' +
'print e(%_#<#{e.full_message}>_);' +
'end' +
'"')
exec.StdIn.WriteLine(encodeURIComponent(document.FullName))
exec.StdIn.Write(encodeURIComponent(document.selection.text))
exec.StdIn.Close()
document.selection.text = decodeURIComponent(exec.StdOut.ReadAll())
アウトプットバー版
// Rubyを実行 (アウトプットバー版).js
'use strict'
// rubyw.exe の場所を指定
var RUBY_PATH = 'C:\\Program Files\\rubyinstaller-2.7.1-1-x64\\bin\\rubyw.exe'
if (document.selection.IsEmpty) {
document.selection.EndOfLine(false, mePosLogical)
document.selection.StartOfLine(true, mePosLogical)
}
var shell = new ActiveXObject('WScript.Shell')
shell.CurrentDirectory = document.Path || shell.SpecialFolders("Desktop")
var exec = shell.Exec(
'"' + RUBY_PATH + '"' +
' -ruri/common -rtimeout' +
' -e "' +
'STDERR.reopen STDOUT;' +
'def self.r(*s) s.each {|x| require x.to_s } end;' +
'def self.e(str, enc=nil) URI.encode_www_form_component(str.to_s, enc).tr(?+, %_ _) end;' +
'$0 = URI.decode_www_form_component(STDIN.gets.rstrip);' +
'$_ = URI.decode_www_form_component(STDIN.read);' +
'def $_.rest;' +
'self =~ /^__END__/ and $\'[1..-1];' +
'end;' +
'begin;' +
'print Timeout.timeout(2) { e(eval($_)) };' +
'rescue Exception => e;' +
'print e(%_#<#{e.full_message}>_);' +
'end' +
'"')
exec.StdIn.WriteLine(encodeURIComponent(document.FullName))
exec.StdIn.Write(encodeURIComponent(document.selection.text))
exec.StdIn.Close()
outputbar.visible = true
outputbar.Writeln(decodeURIComponent(exec.StdOut.ReadAll()))
スポンサーリンク