Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

"it" as default default parameter block for Ruby #2645

Closed

Description

@benoittgt

Hello

A recent discussion was open on Ruby tracker for a proposal about a default block parameter. Even if the idea is good, the proposal is to have a default block parameter named it.

https://bugs.ruby-lang.org/issues/15897

As mentioned in the discussion RSpec should not technically not be impacted.

jeremyevans0 (Jeremy Evans) wrote:

mikegee (Michael Gee) wrote:

RSpec won't break because their "it" requires an argument

Unfortunately this is not accurate. RSpec has a shorthand style like this:

subject { fortytwo } it { is_expected.to eq 42 }

That's a block argument :). In any case, the parser treats it differently as NODE_ITER/NODE_FCALL, not as NODE_VCALL:

I will try today (I am at CookPad Ruby Hack Challenge with you core Ruby members).

I don't think this is a good idea because it could lead to a lot of confusions.

Activity

  1. benoittgt commented on Jul 2, 2019

    @benoittgt
    MemberAuthor

    I open the issue only to have a discussion.

  2. benoittgt commented on Jul 2, 2019

    @benoittgt
    MemberAuthor

    I wrote a test in RSpec core test suite and run using ruby master with an updated patch.

    ~/code/ruby_source_code/install/bin/bundle exec rspec spec/rspec/core_spec.rb

    --- a/spec/rspec/core/example_group_spec.rb
    +++ b/spec/rspec/core/example_group_spec.rb
    @@ -33,6 +33,10 @@ module RSpec::Core
           end
         end
    
    +    it "does not blow up with 'it' patch" do
    +      expect([1, 2].map { it.to_s }).to eq(["1", "2"])
    +    end
    +
    ~/code/ruby_source_code/install/bin/bundle exec rspec spec/rspec/core/example_group_spec.rb --example patch       [15:57:56]
    Run options: include {:full_description=>/patch/}
    
    Randomized with seed 61921
    
    RSpec::Core::ExampleGroup
      does not blow with 'it' patch
    
    Finished in 0.00315 seconds (files took 0.28764 seconds to load)
    1 example, 0 failures
    
    Randomized with seed 61921
    =end
    

    It works. Same with all of the rspec-core test suite.

    Curious about what do you think about this Ruby proposal @JonRowe.

  3. changed the title [-]Ruby proposal for default bloc parameter with "it"[/-] [+]"it" as default default parameter block for Ruby[/+] on Jul 2, 2019
  4. JonRowe commented on Jul 3, 2019

    @JonRowe
    Member

    Thanks for the heads up, I've left some feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions