Skip to content
Browse files

make spaces an integer and use a case statement instead of if

  • Loading branch information...
1 parent 8774128 commit 15cdf55ea162ad6be7a83d7c6e636ff072e2a198 @franc committed
Showing with 9 additions and 7 deletions.
  1. +1 −1 README
  2. +8 −6 hashToCS.rb
View
2 README
@@ -14,4 +14,4 @@ usage:
coffee_script_file.puts output
end
- HashToCs.convert(ruby_hash, "", proc)
+ HashToCs.convert(ruby_hash, 2, proc)
View
14 hashToCS.rb
@@ -13,7 +13,7 @@ module HashToCS
coffee_script_file.puts output
end
- HashToCs.convert(ruby_hash, "", proc)
+ HashToCs.convert(ruby_hash, 2, proc)
=end
@@ -22,18 +22,20 @@ module HashToCS
end
#input is a Ruby hash
- #spaces is a prefix string of spaces used for whitespace significance
+ #spaces is an integer count of spaces to be used as a prefix string for whitespace significance
#proc acts on the output
- def HashToCS.convert(input, spaces, proc=defaultProc)
- if input.is_a? String
+ def HashToCS.convert(input, spaces=0, proc=defaultProc)
+ spaces = " " * spaces
+ case input
+ when String
proc.call spaces + '"' + input + '"' + "\n"
- elsif input.is_a? Array
+ when Array
proc.call spaces + "[\n"
input.each do |a|
convert(a, spaces + " ", proc)
end
proc.call spaces + "]\n"
- elsif input.is_a? Hash
+ when Hash
proc.call spaces + "{\n"
input.each do |k, v|
proc.call spaces + " #{k}:\n"

0 comments on commit 15cdf55

Please sign in to comment.
Something went wrong with that request. Please try again.