Skip to content

Instantly share code, notes, and snippets.

@rickhull
Created December 1, 2017 04:10
Show Gist options
  • Save rickhull/00221b5a04fd9f14c1dc379150890261 to your computer and use it in GitHub Desktop.
Save rickhull/00221b5a04fd9f14c1dc379150890261 to your computer and use it in GitHub Desktop.
def self.def_builtin_commands(delegation_class, command_specs)
for meth, args in command_specs
arg_str = args.collect{|arg| arg.downcase}.join(", ")
call_arg_str = args.collect{
|arg|
case arg
when /^(FILENAME.*)$/
format("expand_path(%s)", $1.downcase)
when /^(\*FILENAME.*)$/
# \*FILENAME* -> filenames.collect{|fn| expand_path(fn)}.join(", ")
$1.downcase + '.collect{|fn| expand_path(fn)}'
else
arg
end
}.join(", ")
d = %Q[def #{meth}(#{arg_str})
#{delegation_class}.#{meth}(#{call_arg_str})
end]
Shell.notify "Define #{meth}(#{arg_str})", Shell.debug?
Shell.notify("Definition of #{meth}: ", d,
Shell.debug.kind_of?(Integer) && Shell.debug > 1)
eval d
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment