<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Edwin Vasquez on Medium]]></title>
        <description><![CDATA[Stories by Edwin Vasquez on Medium]]></description>
        <link>https://medium.com/@edwineinsen?source=rss-c3ac62f667f5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*webb-5uNljK5gNy2.</url>
            <title>Stories by Edwin Vasquez on Medium</title>
            <link>https://medium.com/@edwineinsen?source=rss-c3ac62f667f5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 00:15:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@edwineinsen/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Instance Variables]]></title>
            <link>https://edwineinsen.medium.com/instance-variables-bbb3ca2b5eba?source=rss-c3ac62f667f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbb3ca2b5eba</guid>
            <category><![CDATA[basics-of-programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[instance-variables]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[oop-concepts]]></category>
            <dc:creator><![CDATA[Edwin Vasquez]]></dc:creator>
            <pubDate>Sat, 26 Aug 2023 08:18:45 GMT</pubDate>
            <atom:updated>2023-08-26T08:18:45.041Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jceiI1yr1xnFDmUUdS3m9A.png" /><figcaption>ruby language icon</figcaption></figure><p>Objects can hold their own state by setting <em>instance variables</em>. These variables live within an object and usually are used to store some internal state or data.</p><p>Instance variables always start with an <strong>@</strong>. You can create a new instance variable by setting a variable starting with an <strong>@</strong>. Example:</p><pre>class Repeater<br>  def hear(something)<br>    # Save this &quot;something&quot; that you heard into this new instance variable called @heard<br>    @heard = something<br>  end<br><br>  def repeat<br>    # Return the value of the instance variable into another method<br>    @heard<br>  end<br>end<br><br>repeater = Repeater.new<br>repeater.hear(&quot;Hello&quot;)<br>print repeater.repeat # This prints &quot;Hello&quot;</pre><p>Objects usually set their initial state or values of properties in an <strong>initialize</strong> method, which is automatically called when calling <strong>new</strong> on a class.</p><pre>class Car<br>  def initialize<br>    @doors = 2<br>  end<br><br>  def doors<br>    @doors<br>  end<br>end<br><br>car = Car.new<br>car.doors # returns 2</pre><p>The <strong>initialize</strong> method may also take arguments so that each instance can start with a custom state or values in properties:</p><pre>class Door<br>  def initialize(locked)<br>    # Here takes an argument called &quot;locked&quot;<br>    @locked = locked<br>  end<br>end</pre><p>It is a good practice to consider instance variables private from external reads and writes. We instead define methods to get and set their values. Example:</p><pre>class Door<br>  def initialize<br>    @locked = false<br>  end<br><br>  def locked? # Query methods should be named with a trailing &#39;?&#39;<br>    @locked<br>  end<br><br>  def lock! # Methods which mutate state should have trailing &#39;!&#39;<br>    @locked = true<br>  end<br>end<br><br>door = Door.new<br>door.locked? # returns false<br>door.lock!   # change the value to true of instance variable @locked<br>door.locked? # returns true</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbb3ca2b5eba" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>