File: compose.rb

package info (click to toggle)
ruby-backports 3.25.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,912 kB
  • sloc: ruby: 11,759; makefile: 6
file content (19 lines) | stat: -rw-r--r-- 438 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
unless Proc.method_defined?(:<<) || Proc.method_defined?(:>>)
  class Proc
    def <<(g)
      if lambda?
        lambda { |*args, &blk| call(g.call(*args, &blk)) }
      else
        proc { |*args, &blk| call(g.call(*args, &blk)) }
      end
    end

    def >>(g)
      if lambda?
        lambda { |*args, &blk| g.call(call(*args, &blk)) }
      else
        proc { |*args, &blk| g.call(call(*args, &blk)) }
      end
    end
  end
end