Created
April 23, 2016 20:04
-
-
Save bparanj/b829f58a8ca07406b67f5f444529822c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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