Feature #10327 » bool-falsy-truthy.patch
include/ruby/ruby.h | ||
---|---|---|
VALUE rb_require(const char*);
|
||
RUBY_EXTERN VALUE rb_mBool;
|
||
RUBY_EXTERN VALUE rb_mKernel;
|
||
RUBY_EXTERN VALUE rb_mComparable;
|
||
RUBY_EXTERN VALUE rb_mEnumerable;
|
||
RUBY_EXTERN VALUE rb_mErrno;
|
||
RUBY_EXTERN VALUE rb_mFalsy;
|
||
RUBY_EXTERN VALUE rb_mFileTest;
|
||
RUBY_EXTERN VALUE rb_mGC;
|
||
RUBY_EXTERN VALUE rb_mMath;
|
||
RUBY_EXTERN VALUE rb_mProcess;
|
||
RUBY_EXTERN VALUE rb_mTruthy;
|
||
RUBY_EXTERN VALUE rb_mWaitReadable;
|
||
RUBY_EXTERN VALUE rb_mWaitWritable;
|
||
object.c | ||
---|---|---|
VALUE rb_cData;
|
||
VALUE rb_cNilClass;
|
||
VALUE rb_mBool;
|
||
VALUE rb_cTrueClass;
|
||
VALUE rb_cFalseClass;
|
||
VALUE rb_mTruthy;
|
||
VALUE rb_mFalsy;
|
||
#define id_eq idEq
|
||
#define id_eql idEqlP
|
||
... | ... | |
return Qfalse;
|
||
}
|
||
static VALUE
|
||
rb_bool_append_features(VALUE module, VALUE includeto)
|
||
{
|
||
if ((includeto != rb_cFalseClass) && (includeto != rb_cTrueClass)) {
|
||
rb_raise(rb_eTypeError, "'%s' isn't FalseClass nor TrueClass",
|
||
rb_class2name(includeto));
|
||
}
|
||
return module;
|
||
}
|
||
/*
|
||
* call-seq:
|
||
* Falsy === nil -> true
|
||
* Falsy === false -> true
|
||
* Falsy === true -> false
|
||
* Falsy === <anything_else> -> false
|
||
*
|
||
* Only the objects <i>nil</i> and <i>false</i> respond <code>true</code>.
|
||
* Others respond <code>false</code>.
|
||
*/
|
||
static VALUE
|
||
rb_falsy_rtest(VALUE obj1, VALUE obj2)
|
||
{
|
||
VALUE result;
|
||
result = rb_funcall(obj2, id_eq, 1, Qnil);
|
||
if (RTEST(result)) return Qtrue;
|
||
result = rb_funcall(obj2, id_eq, 1, Qfalse);
|
||
if (RTEST(result)) return Qtrue;
|
||
return Qfalse;
|
||
}
|
||
/*
|
||
* call-seq:
|
||
* Truthy === nil -> false
|
||
* Truthy === false -> false
|
||
* Truthy === true -> true
|
||
* Truthy === <anything_else> -> true
|
||
*
|
||
* Only the objects <i>nil</i> and <i>false</i> respond <code>false</code>.
|
||
* Others respond <code>true</code>.
|
||
*/
|
||
static VALUE
|
||
rb_truthy_rtest(VALUE obj1, VALUE obj2)
|
||
{
|
||
VALUE result;
|
||
result = rb_funcall(obj2, id_eq, 1, Qnil);
|
||
if (!RTEST(result)) {
|
||
result = rb_funcall(obj2, id_eq, 1, Qfalse);
|
||
if (!RTEST(result)) return Qtrue;
|
||
}
|
||
return Qfalse;
|
||
}
|
||
/*
|
||
* call-seq:
|
||
... | ... | |
rb_cData = rb_define_class("Data", rb_cObject);
|
||
rb_undef_alloc_func(rb_cData);
|
||
rb_mBool = rb_define_module("Bool");
|
||
rb_define_singleton_method(rb_mBool, "append_features", rb_bool_append_features, 1);
|
||
rb_cTrueClass = rb_define_class("TrueClass", rb_cObject);
|
||
rb_include_module(rb_cTrueClass, rb_mBool);
|
||
rb_define_method(rb_cTrueClass, "to_s", true_to_s, 0);
|
||
rb_define_alias(rb_cTrueClass, "inspect", "to_s");
|
||
rb_define_method(rb_cTrueClass, "&", true_and, 1);
|
||
... | ... | |
rb_define_global_const("TRUE", Qtrue);
|
||
rb_cFalseClass = rb_define_class("FalseClass", rb_cObject);
|
||
rb_include_module(rb_cFalseClass, rb_mBool);
|
||
rb_define_method(rb_cFalseClass, "to_s", false_to_s, 0);
|
||
rb_define_alias(rb_cFalseClass, "inspect", "to_s");
|
||
rb_define_method(rb_cFalseClass, "&", false_and, 1);
|
||
... | ... | |
* An alias of +false+
|
||
*/
|
||
rb_define_global_const("FALSE", Qfalse);
|
||
/*
|
||
* Falsy RTEST
|
||
*/
|
||
rb_mFalsy = rb_define_module("Falsy");
|
||
rb_define_singleton_method(rb_mFalsy, "===", rb_falsy_rtest, 1);
|
||
/*
|
||
* Truthy RTEST
|
||
*/
|
||
rb_mTruthy = rb_define_module("Truthy");
|
||
rb_define_singleton_method(rb_mTruthy, "===", rb_truthy_rtest, 1);
|
||
}
|
- « Previous
- 1
- 2
- Next »