From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=-1.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 7C3D01F405 for ; Mon, 22 Jan 2024 16:40:51 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=n9Qzpxnc; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=nx1Px7Fh; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 8730581F0F; Mon, 22 Jan 2024 16:40:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1705941643; bh=Zz7zNn8INBYf/xRZRiQhwD7vIvOd4ukFmmvt3mt74jQ=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=n9Qzpxnc/UAP+vgeGN1Ri16CePBLHNJ8piv/sFiuuzD5g/7/tsny6Psju/0Q/uvNH BCg7Zlg80vHCd5c/xPZpxA1cpkphHrU9knZmy8DNFUN5QDvqJ3sjLDCld3UhrJGezB sF+l3oC00dp/WEiTegIq1sroUL32ws1BrBm1l+eg= Received: from csnrwnwx.outbound-mail.sendgrid.net (csnrwnwx.outbound-mail.sendgrid.net [198.37.146.154]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 8C08481F0D for ; Mon, 22 Jan 2024 16:40:39 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=nx1Px7Fh; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=Yy3k4s0Vs749/cx3RQGx5zKEBoC7713u3tMJ34i7kbs=; b=nx1Px7FhZw8Yr+eavPMCMCHYjJg0Xx/PRIsGTm1hJ8Gao5/4bdUmBze/MSahciOONYaY iuy4N8XdEWj/IuF4gAIAbAZ7ZPTGIH/XskmfI5U7BvzhMrazH4R3XYUnzqJpdJlSzoxFX7 GveIbPWBbUVs6odbsPsVKTjlGJF5irYlXb/vsZvP3XsT26wimMNsdGxMgnHr+VUMyuIfUG 9XEt7yUM+rilQiS0EyV4B/iuOxa6IHsFKem+7IoAT9YgoXa0qXNKZhG17fEQoDM8GljRPI riCNrUhVK/RES0gdMXEZVnz1YXnqpno8lLNgn/tqqmAw+XyRjIC8jZ4qToIhT69w== Received: by recvd-646dbb58c-c88xk with SMTP id recvd-646dbb58c-c88xk-1-65AE9A85-19 2024-01-22 16:40:37.511814931 +0000 UTC m=+4561806.227626587 Received: from herokuapp.com (unknown) by geopod-ismtpd-32 (SG) with ESMTP id RULkw2gERRWr6g_Umw8gtA for ; Mon, 22 Jan 2024 16:40:37.455 +0000 (UTC) Date: Mon, 22 Jan 2024 16:40:37 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 20202 X-Redmine-Issue-Author: matheusrich X-Redmine-Sender: matheusrich X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 92929 X-SG-EID: =?us-ascii?Q?3XqQPhAqyKBaCIJPVBiiUg=2FBJ=2Fawrd+4QUdyOQSMUIJiah9H8yd5K+V9IjPq3O?= =?us-ascii?Q?cuogg4GvmnLnkicsy6d9IWyDWROUWFyUhXhneAc?= =?us-ascii?Q?DDySwu9qY4ykvRYfQ0IXICwACgtTZNeKkzer0+T?= =?us-ascii?Q?E7KUtqxT+R0NirKi3IUWdw+vVzvKuotDqOC1Pah?= =?us-ascii?Q?JRoHu4dRLwYQEmx7dNiA5eQKjmbRvs09Kx628OO?= =?us-ascii?Q?BsuZjGkuVpGkHQXRIDBWZ4I+wP=2FWwVnwYUuEEHX?= =?us-ascii?Q?8LDAON81Khek2InCHF0zg=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== Message-ID-Hash: OLWBB5ZDWKTJAR6KH4EDYOHZJWXCGULM X-Message-ID-Hash: OLWBB5ZDWKTJAR6KH4EDYOHZJWXCGULM X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:116369] [Ruby master Feature#20202] Memoized endless method definitions List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "matheusrich (Matheus Richard) via ruby-core" Cc: "matheusrich (Matheus Richard)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20202 has been reported by matheusrich (Matheus Richard). ---------------------------------------- Feature #20202: Memoized endless method definitions https://bugs.ruby-lang.org/issues/20202 * Author: matheusrich (Matheus Richard) * Status: Open * Priority: Normal ---------------------------------------- I propose introducing a shorthand for memoized endless method definitions: ```rb class Foo def bar ||= :memoized_value # It should behave like def bar = (@bar ||= :memoized_value) end ``` Not only is this shorter and (IMO) a natural follow-up for endless method definitions, but it's also a common pattern on Ruby codebases. It's very useful to decompose responsibilities into several objects: ```rb class User def notifications_enabled? = settings.notifications? def enable_notifications = (settings.notifications = true) def disable_notifications = (settings.notifications = false) private def settings = @settings ||= Settings.new(self) end class User::Settings attr_writer :notifications def initialize(user) @user = user @notifications = false end def notifications? = @notifications end u = User.new u.notifications_enabled? # => false u.enable_notifications u.notifications_enabled? # => true ``` In the example, the `settings` method could be rewritten as ```rb def settings ||= Settings.new(self) ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/