Last active
August 29, 2015 14:13
-
-
Save patrobinson/2af3a52b72a2edc5dd8e to your computer and use it in GitHub Desktop.
This file contains 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 javascript_class_type value | |
class_of = lambda { |klass| value.kind_of?(klass) } | |
case | |
when class_of.call(String) | |
return "string" | |
when class_of.call(Fixnum), class_of.call(Float) | |
return "number" | |
when class_of.call(FalseClass), class_of.call(TrueClass) | |
return "boolean" | |
when class_of.call(Array) | |
return "Array/#{self.javascript_class_type(value[0])}" | |
else | |
raise "Unsupported parameter type #{value.class}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment