Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Compatibility:
* Fixed uninitialized variable warnings in core and lib (#1897).
* Make `Thread#backtrace` support omit, length and range arguments.
* Implemented `Range#%`.
* Implemented `rb_obj_is_proc` (#1908, @kipply, @XrXr).
* Fixed the type of the `flags` field of `rb_data_type_t` (#1911).

Changes:
Expand Down
5 changes: 5 additions & 0 deletions spec/ruby/optional/capi/ext/proc_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ VALUE proc_spec_rb_proc_call(VALUE self, VALUE prc, VALUE args) {
return rb_proc_call(prc, args);
}

VALUE proc_spec_rb_obj_is_proc(VALUE self, VALUE prc) {
return rb_obj_is_proc(prc);
}

/* This helper is not strictly necessary but reflects the code in wxRuby that
* originally exposed issues with this Proc.new behavior.
*/
Expand Down Expand Up @@ -61,6 +65,7 @@ void Init_proc_spec(void) {
rb_define_method(cls, "rb_proc_arity", proc_spec_rb_proc_arity, 1);
rb_define_method(cls, "rb_proc_call", proc_spec_rb_proc_call, 2);
rb_define_method(cls, "rb_Proc_new", proc_spec_rb_Proc_new, 1);
rb_define_method(cls, "rb_obj_is_proc", proc_spec_rb_obj_is_proc, 1);
}

#ifdef __cplusplus
Expand Down
19 changes: 19 additions & 0 deletions spec/ruby/optional/capi/proc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@
@p.rb_proc_call(prc, [6, 7]).should == 42
end
end

describe "rb_obj_is_proc" do
it "returns true for Proc" do
prc = Proc.new {|a,b| a * b }
@p.rb_obj_is_proc(prc).should be_true
end

it "returns true for subclass of Proc" do
prc = Class.new(Proc).new {}
@p.rb_obj_is_proc(prc).should be_true
end

it "returns false for non Proc instances" do
@p.rb_obj_is_proc("aoeui").should be_false
@p.rb_obj_is_proc(123).should be_false
@p.rb_obj_is_proc(true).should be_false
@p.rb_obj_is_proc([]).should be_false
end
end
end

describe "C-API when calling Proc.new from a C function" do
Expand Down
2 changes: 1 addition & 1 deletion src/main/c/cext/ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -3885,7 +3885,7 @@ VALUE rb_require_safe(VALUE fname, int safe) {
}

VALUE rb_obj_is_proc(VALUE proc) {
rb_tr_error("rb_obj_is_proc not implemented");
return rb_obj_is_kind_of(proc, rb_cProc);
}

VALUE rb_proc_call_with_block(VALUE self, int argc, const VALUE *argv, VALUE pass_procval) {
Expand Down