<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Joel Hunt</title>
    <description>The latest articles on DEV Community by Joel Hunt (@trailsofink).</description>
    <link>https://dev.to/trailsofink</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2196025%2Fd0b890dd-9982-4e0e-bf85-bcb1f3845b8a.jpeg</url>
      <title>DEV Community: Joel Hunt</title>
      <link>https://dev.to/trailsofink</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/trailsofink"/>
    <language>en</language>
    <item>
      <title>Ruby Expressions as D&amp;D Actions</title>
      <dc:creator>Joel Hunt</dc:creator>
      <pubDate>Thu, 31 Oct 2024 22:22:11 +0000</pubDate>
      <link>https://dev.to/trailsofink/ruby-expressions-as-dd-actions-2c31</link>
      <guid>https://dev.to/trailsofink/ruby-expressions-as-dd-actions-2c31</guid>
      <description>&lt;p&gt;A little background: I am a self-taught UX Dev. I know somethings but I would rank myself as an advanced noob. I know some PHP and some JavaScript. I know somethings but I am woefully lacking in others. I recently started the DPI crash course in hope to make it into their Software Developer Apprenticeship (more info &lt;a href="https://dpi.uillinois.edu/tech-talent-development/apprenticeship/" rel="noopener noreferrer"&gt;here&lt;/a&gt;). Currently I have started learning Ruby in their prerequisite Coding Crash Course.&lt;/p&gt;

&lt;p&gt;I won't recap the whole of my notes, just an analogue of what an expressions is and what it represents. This really helped drive home the concept. Stay with me here, I promise it makes sense, at least in my head. &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3j1gly05fcgcq7gkkt9w.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3j1gly05fcgcq7gkkt9w.jpg" alt="Image description" width="800" height="421"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
I like to think of expressions like a character actions in dnd. Expressions are like actions that you want the character to take. You must have a thing and a thing doing something. &lt;/p&gt;

&lt;p&gt;"DM I want to drink this potion." Potion is an object. (a thing). However, just a thing by itself is not very useful. Drink is the doing part of the action. Our action is that we tell our DM is similar to how we write the most basic of expressions in Ruby. An expression is made up of two main parts, the object and the method. The object is a representation of information. The method is what we are doing with that information or thing. In Ruby this action could be represented with the expression &lt;code&gt;potion.drink&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faqlsptvde07e71m2ze11.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faqlsptvde07e71m2ze11.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
Now we can take this example in a couple different ways. We could give the method an argument of how much we want the potion to restore our health. &lt;code&gt;potion.drink(10)&lt;/code&gt;. For the sake of this example we can take this even farther by nesting another expression inside the expression and assigning it to a variable (inception, almost). &lt;code&gt;drink_potion = potion.drink(health.add(10))&lt;/code&gt;. For the sake of this example lets pretend that the potion class functions like adding a number to a string. Just pretend there is a potion drinking framework out there with me.&lt;/p&gt;

&lt;p&gt;If we wanted to not pretend that there is a fictional dnd ruby framework, this example also kinda works.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;current_health = 2
max_health = 12
potion = 10
drink_potion = currect_health.add(potion)
current_health = drink_potion 
pp current_health # this will return 10 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anyways,&lt;br&gt;
tldr: ruby expressions are like dnd actions trust me bro. &lt;/p&gt;

</description>
      <category>ruby</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
