
lists.sr.ht/~kells/ruby-data-class-lightning-talk/<[email protected]>/mbox
Preview meta tags from the lists.sr.ht website.
General Meta Tags
1- titles was written by %<author>s in %<year>i' + + def to_s + SUMMARY % {title:, author:, year:} + end +end +``` + +```ruby +hobbit = Book.new("The Hobbit", "J.R.R. Tolkien", 1937) +puts hobbit.to_s +=> 'The Hobbit was written by J.R.R. Tolkien in 1937' +``` + +### Creating the Data objects + +Example: + +```ruby +hobbit = Book.new(title: "The Hobbit", author: "J. R. R. Tolkien", year: 1937) +=> <data Book title="The Hobbit", author="J. R. R. Tolkien", year=1937> + +hobbit.author +=> "J. R. R. Tolkien" + +hobbit.year +=> 1937 + +hobbit.title +=> "The Hobbit" +``` + +We can create shallow clones of an instance of Data +Example: + +```ruby + +>> philadelphia = Location[39.9526, -75.1652] +=> #<data Location latitude=39.9526, longitude=-75.1652> +>> philadelphia.latitude +=> 39.9526 +>> philadelphia.longitude +=> -75.1652 +``` + +- Initialize with keyword arguments +- Initialize with positional arguments +- Initialize with brackets (either with keyword or positional arguments) + base-commit: c16dc16959fae3b044be29bf5c7f4c0a4b18f85f -- 2.49.0 From nobody Wed Aug 27 13:22:47 2025 Authentication-Results: mail-a.sr.ht; dkim=pass header.d=gmail.com [email protected] Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by mail-a.sr.ht (Postfix) with ESMTPS id 4126B22174 for <~kells/[email protected]>; Sun, 06 Jul 2025 05:40:38 +0000 (UTC) Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-6faf66905adso16076986d6.2 for <~kells/[email protected]>; Sat, 05 Jul 2025 22:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751780437; x=1752385237; darn=lists.sr.ht; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=32RxPsgPfpf3zRPi60cGR0N11owMS21rT9B4SMO1hh0=; b=SxXcZXDRS2V1+oMutkJ9D65JEHqBTmkvbZXy9Jd6z6scf30aewWdq7Nd1JVuaLy5L2 zWDeAG1nVU/9a/StZG9t7jLBC8qCS6eMkM2vp2GVIKsXRofb8+4XXD26+OrRiK3AhwsV XILR134b1lmPzAuRLR7mHtFjZySHL0Zawxnqa8KSwgaN/YV5viQgFAbsD5YiZLO4ba+s uiPO1yTgP1uGIFQkERYWhAB3EQvHvL5IP1nR3c/rZqU7yps8YC2rEAI8mYJ6rfZTxb1r TGjjP7zuw4mFI23OkIEZVzhPc/KBdRwBBfbvzvRyTsl10gZfb6zlGCYyN7vW0e+7YR3o kVfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751780437; x=1752385237; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=32RxPsgPfpf3zRPi60cGR0N11owMS21rT9B4SMO1hh0=; b=T8RE0dM3g27znz9dWC4iKKATSyBsDFJIIoh302xRruf9Ur9jTeEXbb8VcZZ6wc+8xn r4DEW6AbHLws4bLOpUB2zERa4d5UKb675D6Gfcm3lqNuPaQbSedKuNLExMNutI8ukCfx 9KrpaAjt2Juks6VAhtREBSOShOKSgK1Q0Px1i1ehIPMS8ClN6hTPKYu5qF1la+oRuX6l P7JuEVjLNVdOJqrXXCPUV1zrqm0YwNWy2Fg8Faw/7AzrQw00LR2ixA+qSVmSU8+XwsWn PwOP0InF0CRwiAfEAAl6Gs2W80r1ILZd4iRpMCQ5qQ7M0hVDieoku2eZxhORqlyPM1Bl D+fg== X-Gm-Message-State: AOJu0YxeY0/zV82hkWPpiVFYtSUQ3l6RU7o+DthE/V3yxczhI8AqWS12 3Trqta07B9dz3uOEWhDnLFlFtFizGSuZw5tTLZlzxsaoG/GcKZziCdx9CDoKGQ== X-Gm-Gg: ASbGncsfgLSttKwX+fcHirc9qqiNYWludiT1M9WGHDa/VR2YXaRR8cooxHHiBLYijFm KAPIL0+eghvuS6krJw2E+E2BQsfJkXpvEhjEY9/VZGQbF8pA7uH1/A+rjD5gR+LiFDzqpUCLrg+ 6tvTnEuVe0Dvb1YjLMKU78O5uyeAVj6YYHi+CJZHlKaYOcXFWhyYpeNa6rrXn9Is3KghH68bFS6 +Cnqxa7KX7NJUEqcTu9r1JVfjkH+ZXQhjIHj7Oz/SDdFTBxG0MqFfmPJ9/Cbf70DUrWwta7iuUK uYq44NmWKXpQcGLCl56bu1wRk/yLCfyqQR0fU2aGZvD6r+9+CADdzUfkkGMYlbo66ys7gmwBhKw Lor718LwJD4RlZ6fnzR7wWphx6PUioA== X-Google-Smtp-Source: AGHT+IGptvUTw7zTXwlHV/Kn3pxAVqha4XnxFG7XxPVX86iSOIcuHXNHgb3KOWCOoT3vanFKSDZgng== X-Received: by 2002:a05:6214:226f:b0:6fa:cdc9:8aef with SMTP id 6a1803df08f44-702c8b90ddbmr117389416d6.17.1751780436635; Sat, 05 Jul 2025 22:40:36 -0700 (PDT) Received: from localhost (syn-024-198-168-194.res.spectrum.com. [24.198.168.194]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-702c4cc77b1sm39245676d6.7.2025.07.05.22.40.35 for <~kells/[email protected]> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Jul 2025 22:40:36 -0700 (PDT) Date: Sun, 6 Jul 2025 01:40:34 -0400 From: Victor Goff <[email protected]> To: ~kells/[email protected] Subject: Re: [PATCH DataClassLightningTalk v4 1/1] Add Data class syntax with examples Message-ID: <20250706054034.na5huw7tpffg7hbb@HAL> Mail-Followup-To: ~kells/[email protected] References: <[email protected]> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <[email protected]> On Thu, Jul 03, 2025 at 04:23:46PM -0500, Kelly (Young) Popko wrote: > - Intended purpose of Data class > - Examples of creating instances: > - using keyword arguments > - definining a method on the instance > - bracket notation > > Signed-off-by: Kelly (Young) Popko <[email protected]> > --- > DATA_CLASS_SYNTAX.md | 70 ++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 70 insertions(+) > create mode 100644 DATA_CLASS_SYNTAX.md > > diff --git a/DATA_CLASS_SYNTAX.md b/DATA_CLASS_SYNTAX.md > new file mode 100644 > index 0000000..6fd9c4b > --- /dev/null > +++ b/DATA_CLASS_SYNTAX.md > @@ -0,0 +1,70 @@ > +## Description > + > +From the Ruby Language Data class official documentation, > +> defines simple classes for value-alike objects > +> is meant to be a storage for immutable atomic values > +\- Source: [Ruby 3.2 Data documentation](https://docs.ruby-lang.org/en/3.2/Data.html) > + > +## Syntax > + > +### Create the blueprint (instance of Data class) > + > +We call `Data.define` and pass keyword arguments. > + > +```ruby > +Book = Data.define(:title, :author, :year) > +``` > + > +We can define methods as well if we pass it a block. > + > +```ruby > +Book = Data.define(:title, :author, :year) do > + SUMMARY = '%<title>s was written by %<author>s in %<year>i' > + > + def to_s > + SUMMARY % {title:, author:, year:} > + end > +end > +``` > + > +```ruby > +hobbit = Book.new("The Hobbit", "J.R.R. Tolkien", 1937) > +puts hobbit.to_s > +=> 'The Hobbit was written by J.R.R. Tolkien in 1937' > +``` This should be (with reason in comment: ```ruby hobbit = Book.new("The Hobbit", "J.R.R. Tolkien", 1937) puts hobbit # puts calls `to_s` as part of it's behavior => 'The Hobbit was written by J.R.R. Tolkien in 1937' ``` > + > +### Creating the Data objects > + > +Example: > + > +```ruby > +hobbit = Book.new(title: "The Hobbit", author: "J. R. R. Tolkien", year: 1937) > +=> <data Book title="The Hobbit", author="J. R. R. Tolkien", year=1937> > + > +hobbit.author > +=> "J. R. R. Tolkien" > + > +hobbit.year > +=> 1937 > + > +hobbit.title > +=> "The Hobbit" > +``` > + > +We can create shallow clones of an instance of Data > +Example: > + > +```ruby > + > +>> philadelphia = Location[39.9526, -75.1652] > +=> #<data Location latitude=39.9526, longitude=-75.1652> > +>> philadelphia.latitude > +=> 39.9526 > +>> philadelphia.longitude > +=> -75.1652 > +``` > + > +- Initialize with keyword arguments > +- Initialize with positional arguments > +- Initialize with brackets (either with keyword or positional arguments) > + > > base-commit: c16dc16959fae3b044be29bf5c7f4c0a4b18f85f > -- > 2.49.0 > From nobody Wed Aug 27 13:22:47 2025 Authentication-Results: mail-a.sr.ht; dkim=pass header.d=gmail.com [email protected] Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) by mail-a.sr.ht (Postfix) with ESMTPS id E088121FA8 for <~kells/[email protected]>; Sun, 06 Jul 2025 21:12:29 +0000 (UTC) Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-6fad4e6d949so15047866d6.0 for <~kells/[email protected]>; Sun, 06 Jul 2025 14:12:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751836348; x=1752441148; darn=lists.sr.ht; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=FGZ0DIwec8cxExSr5J/5nesu817FJ9FvLbPCJwRo5I8=; b=APqbjHr/z0vZvGfPTHlHfwxmjEEatyCIwaCkSaLzjrudhgNPxQosakVDZ5rpK96bsF 5Oh+YQBkB8hWKm/WQD1OsoOR/FroQKy830M18exvQFgMrTTWraKj3to+D65TDTTf5dVd 64EnexwfQV2CeUEorwGPHaWBE93VhwhEp6kEdAK0IO1GftZVoAzI6YjtHuE6gnbRylsB R5/dxZaL/HeN+53uowwCWzNeiEgIDD54urdeJSMImRfNf7kem+MC2YTlbLpVJG/psGwV g+1d4a6n333GIcS9l6FpeCUGoLWwKIfpqlNNFPibpKaHSoIU3M9OXLm9FcmVNb2w90Rr rSYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751836348; x=1752441148; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FGZ0DIwec8cxExSr5J/5nesu817FJ9FvLbPCJwRo5I8=; b=uGE5bOodP535TELLF+LEk6suW90YFXVdLs2MM9YUPPdrfzQlDkE9ZJMAIFKYh4L1dy uicj9pN9RGii2rfALPyykcEvGwws2UTmhJN1yBZODBk3p/zMA9N7kr/muPC+P9JQUOfA 3wPklqrT7OJUnOe/zVYYGKtCqykELAymt1eyjdPdeLlZMbaASVVZgyMN/6yLOrDS9JsB GLJRW1EpAcyzMk9c2qUFKg7tWThcxCw8kEi2caWLQEqRSJWDDosnnbJODbJCwIaK9Jch 7Pk1jso8mnjeM4P5601jUZWpTY0xqk+C3eskJfvC+trenC8c9/ZtBuI4G1ZThbeVFyBu gVXw== X-Gm-Message-State: AOJu0YxeDDTmkIscBW1/qXKVDHmhPMIJU18GokeEMQT3c926jdM3IHd6 C8E9TIYnl9Zzkxura2KJh+xpeBDLki2daGbWfMhnCRNdLLhth9td/QiMLqZWHw== X-Gm-Gg: ASbGncsAaALccTZtDn/l9EG3r63EWuLvBdeEQ/za9iZx9selys5pbXs0hIW4V8tiZr2 nwzCRsh5/rjF68lDurCkd1tvLRkMc//wq/Y98YM6wIKXNAg2n+sdL4XeEYG9RLDxKk+KyTloukz QzDbiNYjB/m8mC6ZKMdduYrxfovPR9qqquFlp2ORMexjqmK4cWJSOaZlOq6atQP8VA0vXfoZJO8 Jq7Pn6fG6rEWv0iUVBVXQkRqvQygCeBNOS7runcy1h9Dhk3XtQLkqSvqH+VdFTSgX4T5tXxKuNC nIzICPOwYpsZ63MzB/F6OXd5KYqeMfCCs2QlAnYctuUqnvwSSfuirYufwZZMTnG3I/4g/oNmlJ+ 6SxXpiIKJnsnnGA== X-Google-Smtp-Source: AGHT+IEfXe6qJp6IvGofo2kr823nX7OjBoOMPKDE6r/5KXca2nzPCq6pMmH78meH/DPEfRMXSisOBQ== X-Received: by 2002:a05:6214:5905:b0:6fb:1c3:f527 with SMTP id 6a1803df08f44-702c8ce6b29mr167386956d6.39.1751836348414; Sun, 06 Jul 2025 14:12:28 -0700 (PDT) Received: from localhost ([2607:fb91:22c5:c4a0:35aa:c2c3:e603:3f30]) by smtp.gmail.com with UTF8SMTPSA id 6a1803df08f44-702c4ccd346sm49120036d6.38.2025.07.06.14.12.27 for <~kells/[email protected]> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Jul 2025 14:12:28 -0700 (PDT) Date: Sun, 6 Jul 2025 16:12:26 -0500 From: kelpopko <[email protected]> To: ~kells/[email protected] Subject: Re: [PATCH DataClassLightningTalk v4 1/1] Add Data class syntax with examples Message-ID: <cjexqudyu6qn5c5f7fr4he44daebw2uytfyt2yjzbj4uwywnx6@g3mtyyfvkrpo> References: <[email protected]> <20250706054034.na5huw7tpffg7hbb@HAL> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250706054034.na5huw7tpffg7hbb@HAL> On 25/07/06 01:40AM, Victor Goff wrote: > > + > > +```ruby > > +hobbit = Book.new("The Hobbit", "J.R.R. Tolkien", 1937) > > +puts hobbit.to_s > > +=> 'The Hobbit was written by J.R.R. Tolkien in 1937' > > +``` > > This should be (with reason in comment: > > ```ruby > hobbit = Book.new("The Hobbit", "J.R.R. Tolkien", 1937) > puts hobbit # puts calls `to_s` as part of it's behavior > => 'The Hobbit was written by J.R.R. Tolkien in 1937' > ``` Thanks for catching that! From nobody Wed Aug 27 13:22:47 2025 Authentication-Results: mail-a.sr.ht; dkim=pass header.d=gmail.com [email protected] Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by mail-a.sr.ht (Postfix) with ESMTPS id 0E1AF224EA for <~kells/[email protected]>; Thu, 03 Jul 2025 21:34:01 +0000 (UTC) Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7d5bf3300e0so36113185a.0 for <~kells/[email protected]>; Thu, 03 Jul 2025 14:34:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751578439; x=1752183239; darn=lists.sr.ht; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=TwBkzTw40NOnS0VAb0CHOQDQmehLb8IDseVYKwS2kiU=; b=mcJLVLLMzNnNJfiiUHaVIrVXXO5xOVYoo8qLMDqrXkcYLLoI1PMGqqXQzw4in9xUmh zvu9+xLEYo+SfLvWQlGXcUO8O+xtjX2aVftMd8Z/BPz/r4SQzqDAxAbqEwxIFh/rECrg /bwzgv1d2q1Ln4Rse3ujCU0xM7OK+4ak+cQ2TdtyRM6/RFgpKg02G4Fleb15A+HEpuoX GGSY2VT8XquzCDyGv4RZOndXi/p3xVM/XXaXFYCuOvSZRtgYsLlsEEgMeUKdCY76uYkw o1+pvdI4COu0aQoFCIWL45auTJRQw2kLu4lTYAijRPaQGSLnw7x/a1/jGHe0FUbos5Dq ie8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751578439; x=1752183239; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TwBkzTw40NOnS0VAb0CHOQDQmehLb8IDseVYKwS2kiU=; b=sWBWAsQwAwLtlPnrsOlXb1xahEfx+v2ga/cOVMUg2CoqDNgp0sEqKZDpchce5A3lh1 U3cq7/piDI35q8noSx+SHO0Zgcgy5YzL4Ndhl6rcnSGmEbWFAKjnPnnrFZX7xzCaMhFJ RJdAfWNp0Xp/q+bFrwlq/A1CxqUQJNPkZPakRPGuJhouOf/hCil6x6YD4F1X05ckwgPC AlEauIGAseqjt7kTgf4uKDFawQ1BhW8g+VbdN4irbVytVhdltqZuGUtZpqhaDVc1uNLM LriCPPtdAVDwWtbFeHowLJKoPVyWwMGP8SJZ4tEdRYKZGdYGliaXndJQPFurqigZ7BC4 z8Vw== X-Gm-Message-State: AOJu0Yxt1QVz7NqunDLTsVsVUyIuOWfTr9GDEjoZ4xd6BYuvxC206Ki2 ZoWM8b1PKQErnGKg0hUDaQK7YsiAGmSKjQFx2nYFVR3VkwM+3ShctCi6e+tMCA== X-Gm-Gg: ASbGncsEBZrKntkp/i/TvcjSasmCBpC0TfcPeF9EaCHK8wFdrz99nAZWGagR44YDu7+ gtgLVyQyAgQLfav88Q1Pkz3zcBAmKxlbEGAyUPRAF57bi/BnmmurHd+emTNa8ZCHC3OK5ij96TW Ov3FPF4TjsWzl7e3vprZbdj/0DKls96aKINzQjtf3zK10pDMgnxbAZOOKUGPNbKpfI3d9j+4lGj b9W7QD/PeUjzlCNCIhS4hqy2WErdLJSzSckwGw9Ztc/vZKPe5KP9r7E01urF1xvC15tbYniyYdL YQf9eD9iETKgS0hD/NKTz+bfm3STulzlPhjiRczJdQYF4p8VM1NXYr/Iv2m9DyMC0QE6nyLEsvi l0/tiBUIXnCFLSW34ZwTrl9PKWU8TqWeHiOl5qpe/ X-Google-Smtp-Source: AGHT+IFUSmd5v54Guh7T+SwRRFqbX/XSQ/A4JErQSHSfE+0QVfKr5A+SnYsQaRs0Vle/Cybx68/MaQ== X-Received: by 2002:a05:620a:28c2:b0:7d5:c196:e9bc with SMTP id af79cd13be357-7d5dcc9de04mr76310685a.15.1751578439496; Thu, 03 Jul 2025 14:33:59 -0700 (PDT) Received: from localhost (syn-024-198-168-194.res.spectrum.com. [24.198.168.194]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-702c4d62f2esm3430126d6.118.2025.07.03.14.33.58 for <~kells/[email protected]> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jul 2025 14:33:58 -0700 (PDT) Date: Thu, 3 Jul 2025 17:33:57 -0400 From: Victor Goff <[email protected]> To: ~kells/[email protected] Subject: Re: [PATCH DataClassLightningTalk v4 1/1] Add Data class syntax with examples Message-ID: <20250703213357.yfk62o6i33tcds4w@HAL> Mail-Followup-To: ~kells/[email protected] References: <[email protected]> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <[email protected]> On Thu, Jul 03, 2025 at 04:23:46PM -0500, Kelly (Young) Popko wrote: > - Intended purpose of Data class > - Examples of creating instances: > - using keyword arguments > - definining a method on the instance > - bracket notation > > Signed-off-by: Kelly (Young) Popko <[email protected]> > --- > DATA_CLASS_SYNTAX.md | 70 ++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 70 insertions(+) > create mode 100644 DATA_CLASS_SYNTAX.md > > diff --git a/DATA_CLASS_SYNTAX.md b/DATA_CLASS_SYNTAX.md > new file mode 100644 > index 0000000..6fd9c4b > --- /dev/null > +++ b/DATA_CLASS_SYNTAX.md > @@ -0,0 +1,70 @@ > +## Description > + > +From the Ruby Language Data class official documentation, > +> defines simple classes for value-alike objects > +> is meant to be a storage for immutable atomic values > +\- Source: [Ruby 3.2 Data documentation](https://docs.ruby-lang.org/en/3.2/Data.html) > + > +## Syntax > + > +### Create the blueprint (instance of Data class) > + > +We call `Data.define` and pass keyword arguments. > + > +=> -75.1652 > +``` > + > +- Initialize with keyword arguments > +- Initialize with positional arguments > +- Initialize with brackets (either with keyword or positional arguments) Yes, with brackets, but what kind of brackets? Also, in the IRB, show both? Show in "opposite order" when using latitude and longitude names as well, to show that the keyword arguments do differentiate and it is not imaginary. > + > > base-commit: c16dc16959fae3b044be29bf5c7f4c0a4b18f85f > -- > 2.49.0 >