APIdock / Ruby
/
method

alias_command

ruby latest stable - Class: Shell ::CommandProcessor
alias_command(ali, command, *opts)
public

Creates a command alias at the given alias for the given command, passing any options along with it.

Shell ::CommandProcessor .alias_command  "lsC", "ls", "-CBF", "--show-control-chars"
Shell ::CommandProcessor .alias_command ("lsC", "ls"){|*opts| ["-CBF", "--show-control-chars", *opts]}
# File lib/shell/command-processor.rb, line 436
 def self.alias_command(ali, command, *opts)
 ali = ali.id2name if ali.kind_of?(Symbol)
 command = command.id2name if command.kind_of?(Symbol)
 begin
 if iterator?
 @alias_map[ali.intern] = proc
 eval((d = %[def #{ali}(*opts)
 @shell.__send__(:#{command},
 *(CommandProcessor.alias_map[:#{ali}].call *opts))
 end]), nil, __FILE__, __LINE__ - 1)
 else
 args = opts.collect{|opt| '"' + opt + '"'}.join(",")
 eval((d = %[def #{ali}(*opts)
 @shell.__send__(:#{command}, #{args}, *opts)
 end]), nil, __FILE__, __LINE__ - 1)
 end
 rescue SyntaxError
 Shell.notify "warn: Can't alias #{ali} command: #{command}."
 Shell.notify("Definition of #{ali}: ", d)
 raise
 end
 Shell.notify "Define #{ali} command: #{command}.", Shell.debug?
 Shell.notify("Definition of #{ali}: ", d,
 Shell.debug.kind_of?(Integer) && Shell.debug > 1)
 self
 end

AltStyle によって変換されたページ (->オリジナル) /