Skip to content

Instantly share code, notes, and snippets.

@bparanj
Created April 23, 2016 20:04
Show Gist options
  • Save bparanj/b829f58a8ca07406b67f5f444529822c to your computer and use it in GitHub Desktop.
Save bparanj/b829f58a8ca07406b67f5f444529822c to your computer and use it in GitHub Desktop.
require 'json'
class Transformer
def initialize(string)
@string = string
end
def transformed_string(type)
if type == :json
JSON.parse(@string)
elsif type == :binary
@string.unpack('B*').first
end
end
end
t = Transformer.new('Hello')
x = t.transformed_string(:binary)
p x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment