Sha256: f173fa73b80fb5ea6dd84f0449ef93402e48b5127ce643f509a3839431fda07e
Contents?: true
Size: 763 Bytes
Versions: 31
Compression:
Stored size: 763 Bytes
Contents
# Write a Coder that can encode an Array of Numbers as a String and decode a String into a Number. # Hint: inspect .vs. eval $: << File.expand_path("../../../lib", __FILE__) require 'asir' module ASIR class Coder class Simple < self def _encode obj obj.inspect end def _decode obj raise TypeError unless String === obj Object.send(:eval, obj) end end end end ###################################################################### begin input = [ 1, 2, 3 ] puts "input = #{input.inspect}" coder = ASIR::Coder::Simple.new coder._log_enabled = true output = coder.encode(input) puts "output = #{output.inspect}" result = coder.decode(output) puts "result = #{result.inspect}" end
Version data entries
31 entries across 31 versions & 1 rubygems