Skip to content

Instantly share code, notes, and snippets.

@patrobinson
Last active August 29, 2015 14:13
Show Gist options
  • Save patrobinson/2af3a52b72a2edc5dd8e to your computer and use it in GitHub Desktop.
Save patrobinson/2af3a52b72a2edc5dd8e to your computer and use it in GitHub Desktop.
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