Йончо обнови решението на 10.11.2014 16:33 (преди около 10 години)
+module RBFS
+
+ class File
+ attr_accessor data
+
+ def initialize(data=nil)
+ @data=data
+ end
+
+ def data_type
+ case @data
+ when NilClass then :nil
+ when String then :string
+ when TrueClass , FalseClass then :boolean
+ when Float , Integer then :number
+ when Symbol then :symbol
+ end
+ end
+
+ def self.parse(string_data)
+ key, value = string_data.split(':')
+ case data_type(@data)
+ when 'nil' then new(nil)
+ when 'string' then new(value)
+ when 'boolean' then new(value == 'true')
+ when 'symbol' then new(value.to_sym)
+ when 'number' then Integer(value)
+ end
+ end
+
+ def serialize
+ case @data
+ when NilClass then "nil:"
+ when String then "string:#{@data}"
+ when TrueClass , FalseClass then "boolean:#{@data}"
+ when Symbol then "symbol:#{@data}"
+ when Integer , Float then "number:#{@data}"
+ end
+ end
+ end
+end