Skip to content

Instantly share code, notes, and snippets.

@iHiD
Created September 11, 2012 16:22
Show Gist options
  • Save iHiD/3699640 to your computer and use it in GitHub Desktop.
Save iHiD/3699640 to your computer and use it in GitHub Desktop.
Sketchup
def self.stringify(input)
if input.is_a? String
input.dump
elsif input.is_a? Array
"[" + input.collect{|object| stringify(object)}.join(",") + "]"
elsif input.is_a? Hash
"{" + input.to_a.collect{|key,value| "#{stringify(key)}:#{stringify(value)}"}.join(",") + "}"
elsif input.is_a? Symbol
input.to_s.dump
else
input.to_s
end
end
def self.stringify(input)
output = nil
if input.class == String
output = input.dump
elsif input.class == Array
output = "[" + (input.collect{|object| stringify(object)}).join(",") + "]"
elsif input.class == Hash
output = "{" + (input.to_a.collect{|key,value| stringify(key) + ":" + stringify(value)}).join(",") + "}"
elsif input.class == Symbol
output = input.to_s.dump
else
output = input.to_s
end
return output
end
@noelwarr
Copy link

Ah yes. My coding habbits have changed in favour of is_a?() and #{}.
I wrote this a year ago, so...
Looks much cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment