Method: Sass::Util#json_value_of
- Defined in:
- lib/sass/util.rb
#json_value_of(v) ⇒ String
Converts the argument into a valid JSON value.
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 |
# File 'lib/sass/util.rb', line 964
def json_value_of(v)
case v
when Integer
v.to_s
when String
"\"" + json_escape_string(v) + "\""
when Array
"[" + v.map {|x| json_value_of(x)}.join(",") + "]"
when NilClass
"null"
when TrueClass
"true"
when FalseClass
"false"
else
raise ArgumentError.new("Unknown type: #{v.class.name}")
end
end
|