Feature #14951 ยป teq.patch
defs/id.def | ||
---|---|---|
GE >= GEQ
|
||
Eq == EQ
|
||
Eqq === EQQ
|
||
Teq =? TEQ
|
||
Neq != NEQ
|
||
Not !
|
||
Backquote `
|
object.c | ||
---|---|---|
}
|
||
/**
|
||
* call-seq:
|
||
* obj =? other -> true or false
|
||
*
|
||
* Test Equality -- Returns true if \a obj and \a other are both
|
||
* either truthy or falsy and false otherwise.
|
||
*/
|
||
VALUE
|
||
rb_teq(VALUE obj1, VALUE obj2)
|
||
{
|
||
return (RTEST(obj1) == RTEST(obj2)) ? Qtrue : Qfalse;
|
||
}
|
||
/**
|
||
* Determines if \a obj1 and \a obj2 are equal in terms of
|
||
* \c Object#eql?.
|
||
*
|
||
... | ... | |
rb_define_method(rb_mKernel, "nil?", rb_false, 0);
|
||
rb_define_method(rb_mKernel, "===", rb_equal, 1);
|
||
rb_define_method(rb_mKernel, "=?", rb_teq, 1);
|
||
rb_define_method(rb_mKernel, "=~", rb_obj_match, 1);
|
||
rb_define_method(rb_mKernel, "!~", rb_obj_not_match, 1);
|
||
rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1);
|
parse.y | ||
---|---|---|
%token tCMP RUBY_TOKEN(CMP) "<=>"
|
||
%token tEQ RUBY_TOKEN(EQ) "=="
|
||
%token tEQQ RUBY_TOKEN(EQQ) "==="
|
||
%token tTEQ RUBY_TOKEN(TEQ) "=?"
|
||
%token tNEQ RUBY_TOKEN(NEQ) "!="
|
||
%token tGEQ RUBY_TOKEN(GEQ) ">="
|
||
%token tLEQ RUBY_TOKEN(LEQ) "<="
|
||
... | ... | |
%nonassoc tDOT2 tDOT3
|
||
%left tOROP
|
||
%left tANDOP
|
||
%nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
|
||
%nonassoc tCMP tEQ tEQQ tTEQ tNEQ tMATCH tNMATCH
|
||
%left '>' tGEQ '<' tLEQ
|
||
%left '|' '^'
|
||
%left '&'
|
||
... | ... | |
| tCMP { ifndef_ripper($$ = tCMP); }
|
||
| tEQ { ifndef_ripper($$ = tEQ); }
|
||
| tEQQ { ifndef_ripper($$ = tEQQ); }
|
||
| tTEQ { ifndef_ripper($$ = tTEQ); }
|
||
| tMATCH { ifndef_ripper($$ = tMATCH); }
|
||
| tNMATCH { ifndef_ripper($$ = tNMATCH); }
|
||
| '>' { ifndef_ripper($$ = '>'); }
|
||
... | ... | |
{
|
||
$$ = call_bin_op(p, $1, idEqq, $3, &@2, &@$);
|
||
}
|
||
| arg tTEQ arg
|
||
{
|
||
$$ = call_bin_op(p, $1, idTeq, $3, &@2, &@$);
|
||
}
|
||
| arg tNEQ arg
|
||
{
|
||
$$ = call_bin_op(p, $1, idNeq, $3, &@2, &@$);
|
||
... | ... | |
pushback(p, c);
|
||
return tEQ;
|
||
}
|
||
if (c == '~') {
|
||
if (c == '?') {
|
||
return tTEQ;
|
||
}
|
||
else if (c == '~') {
|
||
return tMATCH;
|
||
}
|
||
else if (c == '>') {
|
test/ruby/test_object.rb | ||
---|---|---|
assert_equal(false, false ^ nil)
|
||
end
|
||
def test_teq
|
||
o = Object.new
|
||
assert_equal(true, o =? Object.new)
|
||
assert_equal(false, o =? false)
|
||
assert_equal(false, o =? nil)
|
||
assert_equal(true, false =? false)
|
||
assert_equal(true, false =? nil)
|
||
assert_equal(false, false =? o)
|
||
assert_equal(true, nil =? false)
|
||
assert_equal(true, nil =? nil)
|
||
assert_equal(false, nil =? o)
|
||
end
|
||
def test_methods
|
||
o = Object.new
|
||
a1 = o.methods
|