Ruby on Rails Thursday, November 29, 2012

On Thu, Nov 29, 2012 at 3:47 AM, comopasta Gr <lists@ruby-forum.com> wrote:
> error_type = Struct.new(:code, :description)
> BAD_JSON = error_type.new("001" , "Problem parsing JSON")
> BAD_XML = error_type.new("002" , "Problem parsing XML")

class MyClass
class APIParseError < StandardError
def initialize(code, lib)
@code = code
@lib = lib
end

def to_s
"#{@code}: Problem parsing #{@lib}"
end
end
end

raise(MyClass::APIParseError.new("001", :XML))
#=> MyClass::MyError: 001: Problem parsing XML

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment