Created
September 11, 2012 16:22
-
-
Save iHiD/3699640 to your computer and use it in GitHub Desktop.
Sketchup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah yes. My coding habbits have changed in favour of is_a?() and #{}.
I wrote this a year ago, so...
Looks much cleaner.