diff --git a/language/method_spec.rb b/language/method_spec.rb index acca074974..35823937c7 100644 --- a/language/method_spec.rb +++ b/language/method_spec.rb @@ -1679,6 +1679,15 @@ def m() = 42 m.should == 42 end + + context "without parenthesis" do + evaluate <<-ruby do + def m = 42 + ruby + + m.should == 42 + end + end end context "with arguments" do @@ -1716,6 +1725,16 @@ def m(...) = mm(...) + mm(...) m("meow", num: 2).should == "meow" * 4 end end + + ruby_version_is ""..."3.0" do + context "inside 'endless' method definitions" do + it "does not allow method calls without parenthesis" do + -> { + eval("def greet(person) = 'Hi, '.concat person") + }.should raise_error(SyntaxError) + end + end + end end describe "Keyword arguments are now separated from positional arguments" do @@ -1824,4 +1843,15 @@ def foo(val) end end end + + describe "Inside 'endless' method definitions" do + context "allows method calls without parenthesis" do + evaluate <<-ruby do + def greet(person) = "Hi, ".concat person + ruby + + greet("Homer").should == "Hi, Homer" + end + end + end end