Class: Firebug::Unserializer
- Inherits:
-
Object
- Object
- Firebug::Unserializer
- Defined in:
- lib/firebug/unserializer.rb
Overview
This class will unserialize a PHP serialized string into a ruby object.
Instance Attribute Summary collapse
-
#str ⇒ StringIOReader
The current value of str.
Class Method Summary collapse
-
.parse(value) ⇒ Object
Convenience method for unserializing a PHP serialized string.
Instance Method Summary collapse
-
#initialize(string) ⇒ Unserializer
constructor
A new instance of Unserializer.
-
#parse ⇒ Hash, ...
Parse a PHP serialized string into a Ruby object.
Constructor Details
#initialize(string) ⇒ Unserializer
Returns a new instance of Unserializer.
14 15 16 |
# File 'lib/firebug/unserializer.rb', line 14 def initialize(string) self.str = StringIOReader.new(string) end |
Instance Attribute Details
#str ⇒ StringIOReader
Returns the current value of str.
10 11 12 |
# File 'lib/firebug/unserializer.rb', line 10 def str @str end |
Class Method Details
.parse(value) ⇒ Object
Convenience method for unserializing a PHP serialized string.
24 25 26 |
# File 'lib/firebug/unserializer.rb', line 24 def self.parse(value) new(value).parse end |
Instance Method Details
#parse ⇒ Hash, ...
Note:
Hashes will be returned with symbolized keys.
Parse a PHP serialized string into a Ruby object.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/firebug/unserializer.rb', line 34 def parse ch = str.getc return if ch.nil? str.getc # : or ; case ch when 'a' parse_enumerable.tap { str.getc } when 's' parse_string when 'i' parse_int when 'd' parse_double when 'b' parse_bool when 'N' nil else raise ParserError, "Unknown token '#{ch}' at position #{str.pos} (#{str.string})" end end |