Skip to content

Instantly share code, notes, and snippets.

@iamvery
Created April 16, 2014 17:07
Show Gist options
  • Save iamvery/10908168 to your computer and use it in GitHub Desktop.
Save iamvery/10908168 to your computer and use it in GitHub Desktop.
module ErrorConversion
def to_error
Error.new(error: name, description: body)
end
end
class Error
attr_reader :error, :description
def initialize(attributes)
@error = attributes[:error]
@description = attributes[:description]
end
end
class Beep
attr_reader :name, :body
def initialize(attributes)
@name = attributes[:name]
@body = attributes[:body]
end
end
beep = Beep.new(name: 'Bonk', body: 'Im bonkin')
beep.extend(ErrorConversion)
beep_error = beep.to_error
puts beep_error.error
puts beep_error.description
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment