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

Version Path
asir-1.2.11 hack_night/solution/prob-4.rb
asir-1.2.10 hack_night/solution/prob-4.rb
asir-1.2.9 hack_night/solution/prob-4.rb
asir-1.2.8 hack_night/solution/prob-4.rb
asir-1.2.7 hack_night/solution/prob-4.rb
asir-1.2.6 hack_night/solution/prob-4.rb
asir-1.2.5 hack_night/solution/prob-4.rb
asir-1.2.3 hack_night/solution/prob-4.rb
asir-1.2.2 hack_night/solution/prob-4.rb
asir-1.2.1 hack_night/solution/prob-4.rb
asir-1.2.0 hack_night/solution/prob-4.rb
asir-1.1.12 hack_night/solution/prob-4.rb
asir-1.1.11 hack_night/solution/prob-4.rb
asir-1.1.10 hack_night/solution/prob-4.rb
asir-1.1.9 hack_night/solution/prob-4.rb
asir-1.1.8 hack_night/solution/prob-4.rb
asir-1.1.7 hack_night/solution/prob-4.rb
asir-1.1.6 hack_night/solution/prob-4.rb
asir-1.1.5 hack_night/solution/prob-4.rb
asir-1.1.4 hack_night/solution/prob-4.rb