Skip to content

Commit

Permalink
Ruby 3.1: Calls without methods inside endless methods
Browse files Browse the repository at this point in the history
A command syntax is allowed in endless method definitions, i.e.,
you can now write

```
def foo = puts "Hello"
```
  • Loading branch information
EduardoGHdez authored and eregon committed Oct 31, 2022
1 parent 433ccef commit 70c8a7b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions language/method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 70c8a7b

Please sign in to comment.