Skip to content

Instantly share code, notes, and snippets.

@shuber

shuber/pipes.c Secret

Created December 10, 2018 06:34
Show Gist options
  • Save shuber/b4d0a10c272d36f6b482ffd491e4cfba to your computer and use it in GitHub Desktop.
Save shuber/b4d0a10c272d36f6b482ffd491e4cfba to your computer and use it in GitHub Desktop.
pipe callsites
# rb_define_method(rb_cArray, "|", rb_ary_or, 1)
rb_ary_or(VALUE ary1, VALUE ary2)
{
VALUE hash, ary3;
ary2 = to_ary(ary2);
if (RARRAY_LEN(ary1) + RARRAY_LEN(ary2) <= SMALL_ARRAY_LEN) {
ary3 = rb_ary_new();
rb_ary_union(ary3, ary1);
rb_ary_union(ary3, ary2);
return ary3;
}
hash = ary_make_hash(ary1);
rb_ary_union_hash(hash, ary2);
ary3 = rb_hash_values(hash);
ary_recycle_hash(hash);
return ary3;
}
# rb_define_method(rb_cFalseClass, "|", false_or, 1);
false_or(VALUE obj, VALUE obj2)
{
return RTEST(obj2)?Qtrue:Qfalse;
}
# rb_define_method(rb_cInteger, "|", int_or, 1)
int_or(VALUE x, VALUE y)
{
if (FIXNUM_P(x)) {
return fix_or(x, y);
}
else if (RB_TYPE_P(x, T_BIGNUM)) {
return rb_big_or(x, y);
}
return Qnil;
}
# rb_define_method(rb_cNilClass, "|", false_or, 1);
false_or(VALUE obj, VALUE obj2)
{
return RTEST(obj2)?Qtrue:Qfalse;
}
# rb_define_method(rb_cTrueClass, "|", true_or, 1);
true_or(VALUE obj, VALUE obj2)
{
return Qtrue;
}
# ext/json/lib/json/generic_object.rb|59
def |(other)
self.class[other.to_hash.merge(to_hash)]
end
# ext/ripper/lib/ripper/lexer.rb|56
def |(i) self.class.new(to_int & i) end
# lib/ipaddr.rb|130
def |(other)
return self.clone.set(@addr | coerce_other(other).to_i)
end
# lib/set.rb|454
def |(enum)
dup.merge(enum)
end
alias + |
alias union |
# lib/shell/filter.rb|102
def |(filter)
filter.input = self
if active?
@shell.process_controller.start_job filter
end
filter
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment