<?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: Dhrumin Thakkar </title>
    <description>The latest articles on DEV Community by Dhrumin Thakkar  (@dhruminthkk).</description>
    <link>https://dev.to/dhruminthkk</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%2F1237300%2Fdc575a74-9dbd-4f60-b072-9ca2dd074286.jpeg</url>
      <title>DEV Community: Dhrumin Thakkar </title>
      <link>https://dev.to/dhruminthkk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dhruminthkk"/>
    <language>en</language>
    <item>
      <title>YAML Magic: Unveiling the Secrets of Aliases, Anchors, and Overrides!</title>
      <dc:creator>Dhrumin Thakkar </dc:creator>
      <pubDate>Fri, 22 Dec 2023 05:48:56 +0000</pubDate>
      <link>https://dev.to/distinction-dev/yaml-magic-unveiling-the-secrets-of-aliases-anchors-and-overrides-bag</link>
      <guid>https://dev.to/distinction-dev/yaml-magic-unveiling-the-secrets-of-aliases-anchors-and-overrides-bag</guid>
      <description>&lt;p&gt;Hey YAML enthusiasts! Ready to dive into the magical world of YAML and uncover some secrets that will make your data structures dance with joy? Buckle up, because today we're unraveling the mysteries of aliases, anchors, and overrides – the enchanting trio that adds a dash of wizardry to your YAML files!&lt;/p&gt;

&lt;h3&gt;
  
  
  Alias All the Things!
&lt;/h3&gt;

&lt;p&gt;Let's kick things off with aliases. Imagine you have a YAML document with repetitive structures, and you wish there was a way to avoid redundancy. Enter aliases! They're like magical shortcuts for your YAML data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;heroes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="nl"&gt;&amp;amp;superman&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Superman&lt;/span&gt;
    &lt;span class="na"&gt;power&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Flight&lt;/span&gt;

  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="nl"&gt;&amp;amp;batman&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Batman&lt;/span&gt;
    &lt;span class="na"&gt;power&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Intelligence&lt;/span&gt;

&lt;span class="na"&gt;justice_league&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;*superman&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;*batman&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this YAML snippet, we've defined two heroes, Superman and Batman, and then we've summoned them to join the Justice League using the &lt;code&gt;*&lt;/code&gt; symbol followed by their alias. It's YAML's way of saying, "Hey, use the properties from this alias here too!" Simple, right?&lt;/p&gt;

&lt;h3&gt;
  
  
  Anchors: Your Data's Home Base
&lt;/h3&gt;

&lt;p&gt;Now, let's talk anchors – the home base for your YAML structures. An anchor is like a bookmark for a specific point in your data, making it easy to reference and reuse.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;countries&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="nl"&gt;&amp;amp;usa&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;United States&lt;/span&gt;
    &lt;span class="na"&gt;population&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;331 million&lt;/span&gt;

  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="nl"&gt;&amp;amp;canada&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Canada&lt;/span&gt;
    &lt;span class="na"&gt;population&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;38 million&lt;/span&gt;

&lt;span class="na"&gt;north_america&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;*usa&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;*canada&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we've anchored the USA and Canada in the &lt;code&gt;countries&lt;/code&gt; list. Later, we effortlessly include them in the &lt;code&gt;north_america&lt;/code&gt; list using the &lt;code&gt;*&lt;/code&gt; symbol, just like with aliases. Anchors help keep your YAML DRY (Don't Repeat Yourself) and your data organized!&lt;/p&gt;

&lt;h3&gt;
  
  
  Overrides: A Splash of Individuality
&lt;/h3&gt;

&lt;p&gt;Now, let's add a touch of individuality to our data with overrides. Sometimes, you want to reuse a structure but tweak certain properties. That's where overrides come in handy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;cities&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="nl"&gt;&amp;amp;nyc&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;New York City&lt;/span&gt;
    &lt;span class="na"&gt;population&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;8.4 million&lt;/span&gt;

  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;*nyc&lt;/span&gt;
    &lt;span class="na"&gt;borough&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Manhattan&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this snippet, we've created an alias for New York City. Then, we've used the &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; syntax to override the properties and add a new one – the borough. This allows us to reuse the city's information while giving it a unique twist. Who said data can't have a personality?&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion: YAML Sorcery Unleashed!
&lt;/h3&gt;

&lt;p&gt;And there you have it – the magical trio of YAML: aliases, anchors, and overrides. With aliases, you can summon data effortlessly. Anchors serve as your data's home base, keeping everything neat and tidy. Overrides add a sprinkle of uniqueness to your structures.&lt;/p&gt;

&lt;p&gt;So, next time you're working with YAML, don your wizard hat, sprinkle a bit of YAML dust, and let the magic of aliases, anchors, and overrides make your data dance with joy! 🎩✨ Happy YAML-ing!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
