Commit b67265c9 authored by anonym's avatar anonym
Browse files

Make Proc into method, so it's available elsewhere.

parent f5a466b7
......@@ -90,28 +90,29 @@ module Dogtail
$vm.execute("rm -f '#{script_path}'")
end
def self.value_to_s(v)
if v == true
'True'
elsif v == false
'False'
elsif v.class == String
"'#{v}'"
elsif [Fixnum, Float].include?(v.class)
v.to_s
else
raise "#{self.class.name} does not know how to handle argument type '#{v.class}'"
end
end
def self.args_to_s(args)
args_list = args
args_hash = nil
if args_list.class == Array && args_list.last.class == Hash
*args_list, args_hash = args_list
end
argify = Proc.new do |v|
if v == true
'True'
elsif v == false
'False'
elsif v.class == String
"'#{v}'"
elsif [Fixnum, Float].include?(v.class)
v.to_s
else
raise "#{self.class.name} does not know how to handle argument type '#{v.class}'"
end
end
(
(args_list.nil? ? [] : args_list.map { |e| argify.call(e) }) +
(args_hash.nil? ? [] : args_hash.map { |k, v| "#{k}=#{argify.call(v)}" })
(args_list.nil? ? [] : args_list.map { |e| self.value_to_s(e) }) +
(args_hash.nil? ? [] : args_hash.map { |k, v| "#{k}=#{self.value_to_s(v)}" })
).join(', ')
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment