File tree Expand file tree Collapse file tree 5 files changed +43
-16
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 5 files changed +43
-16
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ Compatibility:
52
52
* Implemented ` rb_hash_start ` (#1841 , @XrXr ).
53
53
* JCodings has been updated from 1.0.42 to 1.0.45.
54
54
* Joni has been updated from 2.1.25 to 2.1.30.
55
+ * Implemented ` Method#<< ` and ` Method#>> ` (#1821 ).
55
56
56
57
Performance:
57
58
Original file line number Diff line number Diff line change @@ -38,6 +38,22 @@ def double.call(n); n * 2; end
38
38
( f << g ) . lambda? . should == false
39
39
end
40
40
41
+ it "is a Proc when other is lambda" do
42
+ f = proc { |x | x * x }
43
+ g = -> ( x ) { x + x }
44
+
45
+ ( f << g ) . is_a? ( Proc ) . should == true
46
+ ( f << g ) . lambda? . should == false
47
+ end
48
+
49
+ it "is a lambda when self is lambda" do
50
+ f = lambda { |x | x * x }
51
+ g = proc { |x | x + x }
52
+
53
+ ( f << g ) . is_a? ( Proc ) . should == true
54
+ ( f << g ) . lambda? . should == true
55
+ end
56
+
41
57
it "may accept multiple arguments" do
42
58
inc = proc { |n | n + 1 }
43
59
mul = proc { |n , m | n * m }
@@ -91,6 +107,22 @@ def double.call(n); n * 2; end
91
107
( f >> g ) . lambda? . should == false
92
108
end
93
109
110
+ it "is a Proc when other is lambda" do
111
+ f = proc { |x | x * x }
112
+ g = -> ( x ) { x + x }
113
+
114
+ ( f >> g ) . is_a? ( Proc ) . should == true
115
+ ( f >> g ) . lambda? . should == false
116
+ end
117
+
118
+ it "is a lambda when self is lambda" do
119
+ f = lambda { |x | x * x }
120
+ g = proc { |x | x + x }
121
+
122
+ ( f >> g ) . is_a? ( Proc ) . should == true
123
+ ( f >> g ) . lambda? . should == true
124
+ end
125
+
94
126
it "may accept multiple arguments" do
95
127
inc = proc { |n | n + 1 }
96
128
mul = proc { |n , m | n * m }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -30,6 +30,14 @@ def curry(curried_arity = nil)
30
30
self . to_proc . curry ( curried_arity )
31
31
end
32
32
33
+ def >>( other )
34
+ self . to_proc >> other
35
+ end
36
+
37
+ def <<( other )
38
+ self . to_proc << other
39
+ end
40
+
33
41
alias_method :to_s , :inspect
34
42
35
43
end
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ def to_proc
105
105
end
106
106
107
107
def >>( other )
108
- if other . respond_to? ( :lambda? ) && other . lambda?
108
+ if lambda?
109
109
-> ( *args , &block ) do
110
110
other . call ( call ( *args , &block ) )
111
111
end
@@ -117,7 +117,7 @@ def >>(other)
117
117
end
118
118
119
119
def <<( other )
120
- if other . respond_to? ( :lambda? ) && other . lambda?
120
+ if lambda?
121
121
-> ( *args , &block ) do
122
122
call ( other . call ( *args , &block ) )
123
123
end
You can’t perform that action at this time.
0 commit comments