opal/browser/cookies.rb
def [](name)
    matches = `#@document.cookie`.scan(/#{Regexp.escape(name.encode_uri_component)}=([^;]*)/)

    return if matches.empty?

    result = matches.flatten.map {|value|
      JSON.parse(value.decode_uri_component)
    }

    result.length == 1 ? result.first : result
  end
def [](name)
    matches = `#@document.cookie`.scan(/#{Regexp.escape(name.encode_uri_component)}=([^;]*)/)

    return if matches.empty?

    result = matches.flatten.map {|value|
      JSON.parse(value.decode_uri_component)
    }

    result.length == 1 ? result.first : result
  end
Create a new {Cookies} wrapper.

 @param document [native] the native document object
 Access the cookie with the given name.

 @param name [String] the name of the cookie

 @return [Object]