Skip to content

Commit

Permalink
Add NameError#name. Fix NameError.new and NameError.initialize.…
Browse files Browse the repository at this point in the history
… Enable 2nd argument for `NameError.new` in C API.
  • Loading branch information
monaka committed Apr 4, 2013
1 parent 1efb1bb commit edd0a62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions mrblib/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ class TypeError < StandardError

# ISO 15.2.31
class NameError < StandardError
attr_accessor :name

def new(message="NameError", name=nil)
initialize(message, name)
end

def initialize(message=nil, name=nil)
@name = name
super(message)
end
end

# ISO 15.2.32
Expand Down
4 changes: 2 additions & 2 deletions src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...)
argv[0] = mrb_vformat(mrb, fmt, args);
va_end(args);

argv[1] = mrb_symbol_value(id); /* ignore now */
exc = mrb_class_new_instance(mrb, 1, argv, E_NAME_ERROR);
argv[1] = mrb_symbol_value(id);
exc = mrb_class_new_instance(mrb, 2, argv, E_NAME_ERROR);
mrb_exc_raise(mrb, exc);
}

Expand Down

0 comments on commit edd0a62

Please sign in to comment.