Ruby 1.9.3 リファレンスマニュアル > ライブラリ一覧 > shell/command-processorライブラリ > Shell::CommandProcessorクラス
クラスの継承リスト: Shell::CommandProcessor < Object < Kernel < BasicObject
add_delegate_command_to_shell(id)[permalink][rdoc][TODO]
Shell 自体を初期化する時に呼び出されるメソッドです。 ユーザが使用することはありません。
alias_command(alias, command, *opts) -> self[permalink][rdoc]alias_command(alias, command, *opts) { ... } -> self[TODO]
alias_map -> Hash[permalink][rdoc]Shell::CommandProcessor.alias_command で定義したエイリアスの一覧を返します。
def_builtin_commands(delegation_class, commands_specs) -> ()[permalink][rdoc][TODO]
def_system_command(command, path = command) -> ()[permalink][rdoc][TODO]
与えられたコマンドをメソッドとして定義します。
initialize -> ()[permalink][rdoc][TODO]
このクラスを初期化します。
install_builtin_commands -> ()[permalink][rdoc]ビルトインコマンドを定義します。
install_system_commands(prefix = "sys_") -> ()[permalink][rdoc]全てのシステムコマンドをメソッドとして定義します。
既に定義されているコマンドを再定義することはありません。 デフォルトでは全てのコマンドに "sys_" というプレフィクスが付きます。 また、メソッド名として使用できない文字は全て "_" に置換してメソッドを定義します。 このメソッドの実行中に発生した例外は単に無視されます。
method_added(id)[permalink][rdoc][TODO]
このクラスに定義されたメソッドを Shell にも定義するためのフックです。
new(shell)[permalink][rdoc][TODO]
run_config -> ()[permalink][rdoc]ユーザのホームディレクトリに "~/.rb_shell" というファイルが存在すれば、それを Kernel.#load します。
存在しない時は何もしません。
unalias_command(alias) -> self[permalink][rdoc]エイリアスを削除します。
undef_system_command(command) -> self[permalink][rdoc]与えられたコマンドを削除します。
test(command, file1, file2 = nil) -> bool | Time | Integer | nil[permalink][rdoc]self[command, file1, file2 = nil] -> bool | Time | Integer | nilKernel.#test や FileTest のメソッドに処理を委譲します。
require 'shell'
Shell.verbose = false
sh = Shell.new
begin
sh.mkdir("foo")
rescue
end
p sh[?e, "foo"] # => true
p sh[:e, "foo"] # => true
p sh["e", "foo"] # => true
p sh[:exists?, "foo"] # => true
p sh["exists?", "foo"] # => true
[SEE_ALSO] Kernel.#test, FileTest
append(to, filter) -> Shell::AppendFile | Shell::AppendIO[permalink][rdoc][TODO]
atime(filename) -> Time[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.atime
basename(filename, suffix = "") -> String[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.basename
blockdev?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#blockdev?
cat(*files) -> Shell::Filter[permalink][rdoc]実行すると, それらを内容とする Filter オブジェクトを返します.
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}
chardev?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#chardev?
check_point[permalink][rdoc]finish_all_jobs[TODO]
chmod(mode, *filename) -> Integer[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.chmod
chown(owner, group, *filename) -> Integer[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.chown
concat(*jobs) -> Shell::Concat[permalink][rdoc][TODO]
ctime(filename) -> Time[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.ctime
delete(*filename) -> Integer[permalink][rdoc]rm(*filename) -> IntegerFile クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.delete
directory?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#directory?
dirname(filename) -> String[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.dirname
echo(*strings) -> Shell::Filter[permalink][rdoc]実行すると, それらを内容とする Filter オブジェクトを返します.
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}
executable?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#executable?
executable_real?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#executable_real?
exist?(file) -> bool[permalink][rdoc]exists?(file) -> boolFileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#exist? FileTest.#exists?
expand_path(path) -> String[permalink][rdoc]Fileクラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.expand_path
file?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#file?
find_system_command(command)[permalink][rdoc][TODO]
foreach(path = nil, &block) -> ()[permalink][rdoc]pathがファイルなら, File#foreach pathがディレクトリなら, Dir#foreach の動作をします。
使用例
require 'shell'
Shell.verbose = false
sh = Shell.new
sh.foreach("/tmp"){|f|
puts f
}
ftype(filename) -> String[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.ftype
glob(patten) -> Shell::Filter[permalink][rdoc]実行すると, それらを内容とする Filter オブジェクトを返します.
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}
[SEE_ALSO] Dir.[]
grpowned?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#grpowned?
identical?[permalink][rdoc][TODO]
join(*item) -> String[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.join
link(old, new) -> 0[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.link
lstat(filename) -> File::Stat[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.lstat
mkdir(*path) -> Array[permalink][rdoc]Dir.mkdirと同じです。 (複数可)
使用例
require 'shell'
Shell.verbose = false
sh = Shell.new
begin
p sh.mkdir("foo") #=> ["foo"]
rescue => err
puts err
end
mtime(filename) -> Time[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.mtime
notify(*opts) { ... } -> ()[permalink][rdoc][TODO]
open(path, mode) -> File | Dir[permalink][rdoc]path がファイルなら、 File.open path がディレクトリなら、 Dir.open の動作をします。
out(dev = STDOUT, &block) -> ()[permalink][rdoc]Shell#transact を呼び出しその結果を dev に出力します。
使用例:
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
File.open("out.txt", "w"){ |fp|
sh.out(fp) {
system("ls", "-l") | head("-n 3")
}
}
owned?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#owned?
pipe?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#pipe?
readable?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#readable?
readable_real?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#readable_real?
readlink(path) -> String[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.readlink
rehash -> {}[permalink][rdoc]登録されているシステムコマンドの情報をクリアします。 通常、使うことはありません。
rename(from, to) -> 0[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.rename
rmdir(*path) -> ()[permalink][rdoc]Dir.rmdirと同じです。 (複数可)
setgid?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#setgid?
setuid?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#setuid?
size(file) -> Integer[permalink][rdoc]size?(file) -> Integer | nilFileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#size FileTest.#size?
socket?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#socket?
split(pathname) -> [String][permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.split
stat(filename) -> File::Stat[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.stat
sticky?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#sticky?
symlink(old, new) -> 0[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.symlink
symlink?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#symlink?
system(command, *opts) -> Shell::SystemCommand[permalink][rdoc]command を実行する.
使用例:
require 'shell'
Shell.verbose = false
sh = Shell.new
print sh.system("ls", "-l")
Shell.def_system_command("head")
sh.system("ls", "-l") | sh.head("-n 3") > STDOUT
tee(file) -> Shell::Filter[permalink][rdoc]実行すると, それらを内容とする Filter オブジェクトを返します.
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}
transact { ... } -> object[permalink][rdoc]ブロック中で shell を self として実行します。
例:
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact{
system("ls", "-l") | head > STDOUT
# transact の中では、
# sh.system("ls", "-l") | sh.head > STDOUT と同じとなる。
}
truncate(path, length) -> 0[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.truncate
unlink(path) -> self[permalink][rdoc]path がファイルなら File.unlink、path がディレクトリなら Dir.unlink の動作をします。
[SEE_ALSO] File.unlink, Dir.unlink
utime(atime, mtime, *filename) -> Integer[permalink][rdoc]File クラスにある同名のクラスメソッドと同じです.
[SEE_ALSO] File.utime
world_readable?[permalink][rdoc][TODO]
world_writable?[permalink][rdoc][TODO]
writable?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#writable?
writable_real?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#writable_real?
zero?(file) -> bool[permalink][rdoc]FileTest モジュールにある同名のクラスメソッドと同じです.
[SEE_ALSO] FileTest.#zero?
NoDelegateMethods -> [String][permalink][rdoc]内部で使用する定数です。