GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Method call in a block could compare to `&:method_name` too · Issue #201 · fastruby/fast-ruby

Method call in a block could compare to &:method_name too #201

New issue
Copy link
New issue
Copy link
Open
Open
Method call in a block could compare to &:method_name too#201
Copy link
Assignees
JuanVqz
Labels
Suggestion

Description

@arielj
arielj
opened on Jul 6, 2022
Issue body actions

This test https://github.com/fastruby/fast-ruby/blob/master/code/general/block-apply-method.rb is comparing:

def fast
  [1, 2, 3].map { |n| do_something(n) }
end

def slow
  [1, 2, 3].map(&method(:do_something))
end

We could have one more test:

def other
  [1, 2, 3].map(&:do_something)
end

Also, I think the names fast and slow shouldn't be used for the methods, the names should describe what the method does, not which one is faster?

Reacted by Juan Vásquez

Activity

  1. ashwinisukale
    added
    Suggestion
    on Oct 11, 2022
  2. ashwinisukale commented on Oct 11, 2022

    @ashwinisukale
    ashwinisukale
    on Oct 11, 2022
    More actions

    @arielj I guess name fast and slow just indicate which way is faster. In this case if we should not use &method because its slower.

  3. JuanVqz
    self-assigned this
    on Sep 29, 2026
  4. JuanVqz commented on Sep 29, 2026

    @JuanVqz
    JuanVqz
    on Sep 29, 2026
    Member
    More actions

    Hey @arielj, I tried your suggested addition, but [1, 2, 3].map(&:do_something) calls n.do_something instead of do_something(n), so n never gets passed as the argument and Ruby raises:

      private method 'do_something' called for an instance of Integer (NoMethodError)
    

    Am I missing something? What did you have in mind for this case?

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

Metadata

Metadata

Assignees

  • @JuanVqz
    JuanVqz

Labels

Suggestion

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.