[#108771] [Ruby master Bug#18816] Ractor segfaulting MacOS 12.4 (aarch64 / M1 processor) — "brodock (Gabriel Mazetto)" <noreply@...>

Issue #18816 has been reported by brodock (Gabriel Mazetto).

8 messages 2022/06/05

[#108802] [Ruby master Feature#18821] Expose Pattern Matching interfaces in core classes — "baweaver (Brandon Weaver)" <noreply@...>

Issue #18821 has been reported by baweaver (Brandon Weaver).

9 messages 2022/06/08

[#108822] [Ruby master Feature#18822] Ruby lack a proper method to percent-encode strings for URIs (RFC 3986) — "byroot (Jean Boussier)" <noreply@...>

Issue #18822 has been reported by byroot (Jean Boussier).

18 messages 2022/06/09

[#108937] [Ruby master Bug#18832] Suspicious superclass mismatch — "fxn (Xavier Noria)" <noreply@...>

Issue #18832 has been reported by fxn (Xavier Noria).

16 messages 2022/06/15

[#108976] [Ruby master Misc#18836] DevMeeting-2022-07-21 — "mame (Yusuke Endoh)" <noreply@...>

Issue #18836 has been reported by mame (Yusuke Endoh).

12 messages 2022/06/17

[#109043] [Ruby master Bug#18876] OpenSSL is not available with `--with-openssl-dir` — "Gloomy_meng (Gloomy Meng)" <noreply@...>

Issue #18876 has been reported by Gloomy_meng (Gloomy Meng).

18 messages 2022/06/23

[#109052] [Ruby master Bug#18878] parse.y: Foo::Bar {} is inconsistently rejected — "qnighy (Masaki Hara)" <noreply@...>

Issue #18878 has been reported by qnighy (Masaki Hara).

9 messages 2022/06/26

[#109055] [Ruby master Bug#18881] IO#read_nonblock raises IOError when called following buffered character IO — "javanthropus (Jeremy Bopp)" <noreply@...>

Issue #18881 has been reported by javanthropus (Jeremy Bopp).

9 messages 2022/06/26

[#109063] [Ruby master Bug#18882] File.read cuts off a text file with special characters when reading it on MS Windows — magynhard <noreply@...>

Issue #18882 has been reported by magynhard (Matth辰us Johannes Beyrle).

15 messages 2022/06/27

[#109081] [Ruby master Feature#18885] Long lived fork advisory API (potential Copy on Write optimizations) — "byroot (Jean Boussier)" <noreply@...>

Issue #18885 has been reported by byroot (Jean Boussier).

23 messages 2022/06/28

[#109083] [Ruby master Bug#18886] Struct aref and aset don't trigger any tracepoints. — "ioquatix (Samuel Williams)" <noreply@...>

Issue #18886 has been reported by ioquatix (Samuel Williams).

8 messages 2022/06/29

[#109095] [Ruby master Misc#18888] Migrate ruby-lang.org mail services to Google Domains and Google Workspace — "shugo (Shugo Maeda)" <noreply@...>

Issue #18888 has been reported by shugo (Shugo Maeda).

16 messages 2022/06/30

[ruby-core:109000] [Ruby master Feature#18644] Coerce anything callable to a Proc

From: "joel@... (Joel Drapper)" <noreply@...>
Date: 2022-06-18 17:28:13 UTC
List: ruby-core #109000
Issue #18644 has been updated by joel@drapper.me (Joel Drapper).


I really like the first option but unfortunately it makes every object respond to `to_proc` even when they don't respond to `call`. Perhaps a third option is for the & operator to try to coerce using `to_proc` and failing that, try `method(:call).to_proc` if the object responds to `call`.

Alternatively there might be a way to provide a default definition for `to_proc` on only objects that respond to `call`. Here's a hacky way to do that in Ruby.

```ruby
class Object
  def method_missing(name, ...)
    if name == :to_proc && respond_to?(:call)
      if respond_to?(:define_method)
        define_method(name) { method(:call).to_proc }
      else
        define_singleton_method(name) { method(:call).to_proc }
      end

      method(:call).to_proc
    else
      super
    end
  end

  def respond_to_missing?(name, ...)
    name == :to_proc && respond_to?(:call, ...) || super
  end
end
```

----------------------------------------
Feature #18644: Coerce anything callable to a Proc
https://bugs.ruby-lang.org/issues/18644#change-98112

* Author: waiting_for_dev (Marc Busqu辿)
* Status: Open
* Priority: Normal
----------------------------------------
Functional objects are increasingly popular in Ruby. Having objects that respond to `#call` makes them interchangeable with a `Proc`.

However, when you need to perform some Proc-specific operation, like currying, you have to break the abstraction and ask for the type of object. Example:

```ruby
(callable.is_a?(Proc) ? callable : callable.method(:call)).curry[value]
```

Because of https://bugs.ruby-lang.org/issues/18620, it's not possible to make them polymorphic by taking the `:call` method:

```ruby
callable.method(:call).curry[value] # won't work!
```

Consequently, I propose adding a built-in Ruby way to coerce anything callable to a proc (examples in Ruby):

### Option 1: `Object#to_proc`

```ruby
class Object
  def to_proc
    return method(:call).to_proc if respond_to?(:call)
  
    raise "Needs to respond to :call"
  end
end

class Proc
  def to_proc
    self
  end
end

callable.to_proc.curry[value]
```

### Option 2. `Kernel#Proc`

```ruby
class Kernel
  def Proc(value)
    if value.is_a?(::Proc)
      value
    elsif value.respond_to?(:call)
      value.method(:call).to_proc
    else
      raise "Needs to implement :call"
    end
  end
end

Proc(callable).curry[value]
```



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

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next