<?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 Austin Miller on Medium]]></title>
        <description><![CDATA[Stories by Austin Miller on Medium]]></description>
        <link>https://medium.com/@aumi9292?source=rss-be9d675ac7b9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fMjTE5Sg3PoRQnCQ</url>
            <title>Stories by Austin Miller on Medium</title>
            <link>https://medium.com/@aumi9292?source=rss-be9d675ac7b9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:31:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aumi9292/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[Rack: Part II]]></title>
            <link>https://aumi9292.medium.com/rack-part-ii-5dc89e9d89d8?source=rss-be9d675ac7b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/5dc89e9d89d8</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[launch-school]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Austin Miller]]></dc:creator>
            <pubDate>Thu, 29 Oct 2020 21:56:19 GMT</pubDate>
            <atom:updated>2020-10-29T21:56:19.271Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the second in a series of two articles that discuss the Rack RubyGem — what it is, where it sits in server-side development, what it means for an application to be Rack-based, and what Rack accomplishes for developers behind the scenes.</p><p>This article builds on the fundamental concepts of Rack discussed in the first article and focuses on the concept of Rack middleware, what qualifies a Ruby application to be a Rack middleware, and what middlewares can do for your application. We’ll implement two Rack middleware applications for my_app.rb that we worked on earlier and tell Rack to use our middleware stack when it runs our web application.</p><p>You can find the first article <a href="https://aumi9292.medium.com/rack-part-i-6bb268dde211">here</a>.</p><h3>What is Rack middleware?</h3><p>Rack is an interface between an application and an application server. It abstracts away the specifics of handling HTTP requests with a call method, and even works with other servers to handle necessary socket programming to start a server. But it does even more.</p><p>Rack allows you to chain Rack-based classes together. You can write your own Rack-based applications to chain to your primary application, or you can use some of the <a href="https://github.com/rack/rack/wiki/List-of-Middleware">many</a> middleware applications that Rack includes in its library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*Ox1CDN5vpqjoE7cx2ZyfZg.png" /></figure><p>Practically speaking, Rack middleware allows developers to build in many functionalities to their applications, from logging to basic authentication to stopping spam — before they even start working on their application!</p><h3>How does middleware work?</h3><p>As we touched on earlier, Rack-based applications must define a call method. The call method must take one argument and return a 3-item Array with what will be used to form a response status, response headers, and response body.</p><p>Classes that satisfy these requirements can be chained together. This implies that we can chain as many so-called middleware applications to our app as we want. Many different small, modular applications can be chained together to create a middleware stack of technologies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ojqEaFUMeBt4VQj2" /><figcaption>Photo by <a href="https://unsplash.com/@juliakadel?utm_source=medium&amp;utm_medium=referral">Julia Kadel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Let’s work with the simple Rack-based application we set up earlier and add a FriendlyGreeting middleware class to give it some (minimal) functionality. Here’s our simple MyApp class.</p><pre>class MyApp<br>  def call(env)<br>    [&#39;200&#39;, { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, [&quot;hello world&quot;]]<br>  end<br>end</pre><pre>Rack::Handler::WEBrick.run MyApp.<em>new</em></pre><p>To give our Rack-based application some more functionality, without changing anything in the MyApp class itself, let’s define a new class. Let’s say we want to display a friendlier greeting in the browser.</p><pre>class FriendlyGreeting<br>  def initialize(app)<br>    @app = app<br>  end<br>end</pre><p>To start, middleware applications must be defined with an initialize method. The initialize method must take one argument. When ::new is invoked on FriendlyGreeting, an instance of the application one level down the chain will be passed in. The status code, response headers, and response body will then be accessible in our new middleware class. In our simple example, we’d just like to access the response body and prepend it with a friendlier greeting.</p><p>Our new class must also adhere to Rack specifications, so let’s write our FriendlyGreeting#call method with these requirements in mind.</p><pre>class FriendlyGreeting<br>  def initialize(app)<br>    @app = app<br>  end</pre><pre>  def call(env)<br>    body = @app.call(env).last</pre><pre>    [<br>      &#39;200&#39;, <br>      { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, <br>      body.<em>prepend</em>(&quot;A warm welcome to you!\n&quot;)<br>    ]<br>  end<br>end</pre><p>In our call implementation, we actually invoke MyApp#call and pass in env. We then invoke Array#last to access the third element of the return value of MyApp#call, which will be our response body. Finally, we just prepend it with another string and a newline.</p><p>The final piece of the puzzle is to tell Rack how to run our chained applications. We can invoke the same Rack::Handler::WEBrick.run method, but what should we pass in as our application?</p><p>If we think about our FriendlyGreeting class, we define our initialize method to take an argument, which should be an app. This points us in the right direction. We should pass in an instance of the FriendlyGreeting class, which should take an instance of MyApp as an argument.</p><pre>class MyApp<br>  def call(env)<br>    [&#39;200&#39;, { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, [&quot;hello world&quot;]]<br>  end<br>end</pre><pre>class FriendlyGreeting<br>  def initialize(app)<br>    @app = app<br>  end</pre><pre>  def call(env)<br>    body = @app.call(env).last</pre><pre>    [<br>      &#39;200&#39;, <br>      { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, <br>      body.<em>prepend</em>(&quot;A warm welcome to you!\n&quot;)<br>    ]<br>  end<br>end</pre><pre>Rack::Handler::WEBrick.run FriendlyGreeting.<em>new</em>(MyApp.<em>new</em>)</pre><p>When we run ruby myapp.rb in the command line and visit the browser, we should see our more friendly greeting precede our original greeting.</p><h3>Rack Builder</h3><p>This is great. Rack abstracts away sockets and servers, HTTP requests and responses, and even gives us the opportunity to build in modular, reusable chunks of code to accomplish common development tasks.</p><p>One last topic we’ll briefly touch on before we wrap up this discussion is Rack::Builder. Rack::Builder is a DSL that gives us the use method to more concisely incorporate middlewares with our web application. Let’s say we wanted to add one more middleware to our application, perhaps a Wave class that displays one more greeting before our other greetings in the browser, without touching either of our two existing classes.</p><p>Let’s implement a Wave class, define an initialize method that will take one argument and, assign it to @app , and define a call method that will take one argument for the Hash of information about the request. Finally, let’s tell Rack to run our three-level application.</p><pre>class MyApp<br>  def call(env)<br>    [&#39;200&#39;, { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, [&quot;hello world&quot;]]<br>  end<br>end</pre><pre>class FriendlyGreeting<br>  def initialize(app)<br>    @app = app<br>  end</pre><pre>  def call(env)<br>    body = @app.call(env).last</pre><pre>    [<br>      &#39;200&#39;, <br>      { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, <br>      body.<em>prepend</em>(&quot;A warm welcome to you!\n&quot;)<br>    ]<br>  end<br>end</pre><pre>class Wave<br>  def initialize(app)<br>    @app = app<br>  end</pre><pre>  def call(env)<br>    body = @app.call(env).last<br>   <br>    [<br>     &#39;200&#39;, <br>     { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, <br>     body.<em>prepend</em>(&quot;Wave from afar!\n&quot;)<br>    ]<br>  end <br>end</pre><pre>Rack::Handler::WEBrick.run Wave.<em>new</em>(FriendlyGreeting.<em>new</em>(MyApp.<em>new</em>))</pre><p>This works, but you can see that it’s starting to get a little messy. What if your application used 10 different middlewares?</p><p>That’s where Rack::Builder comes in. Rather than nesting instances of classes together to pass to ::run, we can simply invoke Rack::Builder::use to accomplish this is a cleaner syntax. To implement this in the simplest way, we’ll create a config.ru rackup file in the same directory as our myapp.rb file and require our myapp.rb file there. We’ll have one file with our three classes and one file for our rack configuration.</p><pre>#myapp.rb<br><em>#require &#39;rack&#39;</em></pre><pre>class MyApp<br>  def call(env)<br>    [&#39;200&#39;, { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, [&quot;hello world&quot;]]<br>  end<br>end</pre><pre>class FriendlyGreeting<br>  def initialize(app)<br>    @app = app<br>  end</pre><pre>  def call(env)<br>    body = @app.call(env).last</pre><pre>    [<br>      &#39;200&#39;, <br>      { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, <br>      body.<em>prepend</em>(&quot;A warm welcome to you!\n&quot;)<br>    ]<br>  end<br>end</pre><pre>class Wave<br>  def initialize(app)<br>    @app = app<br>  end</pre><pre>  def call(env)<br>    body = @app.call(env).last</pre><pre>    [<br>     &#39;200&#39;, <br>     { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, <br>     body.<em>prepend</em>(&quot;Wave from afar!\n&quot;)<br>    ]<br>  end <br>end</pre><p>Note that if we run our config.ru file to start a server and run our application, we don’t need to require &#39;rack&#39; in our main .rb file. Running .ru files using the rackup command automatically requires Rack. We’re no longer invoking any Rack methods in our main .rb file. That logic has been separated into our config.ru file.</p><pre><em>#config.ru<br>require_relative</em> &quot;myapp&quot;</pre><pre>use Wave<br>use FriendlyGreeting</pre><pre>run MyApp.<em>new</em></pre><p>The .ru file extension will allow us to invoke Rack’s use method and run method without explicitly prefixing them with classes and modules. We will also run the program in the command line using rackup config.ru, which is a command provided by the Rack gem available to run .ru files.</p><p>We can list out as many enclosing middlewares as we need by invoking use. This will also preserve the order in which middlewares are used — the last-listed middleware uses the return value of the main application, the second-to-last middleware uses the return value of the last middleware, etc., etc..</p><p>Rack middlewares make Rack a powerful part of your web application. You can incorporate as many or as few modular classes you need for your app, building as much or as little logic into your program as you’d like.</p><h3>Conclusion</h3><p>In these articles, we’ve talked about Rack. Rack is the 9th-most downloaded gem and a powerful interface.</p><p><strong>Rack …</strong></p><ul><li><strong>Abstracts low-level tasks</strong> like parsing information from HTTP requests and formatting the return value of your application back into an HTTP response that the server can understand. Applications can then be fully focused on business logic .</li><li><strong>Generalizes application-to-server communication</strong>. Rack-based apps — whether they’re written using Ruby, Sinatra, Rails, or another framework — can establish socket connections using any Rack-supported servers, whether that’s WEBrick, Puma, Passenger, etc..</li><li><strong>Provides an architecture for using modular pieces of functionality</strong>. Rack middlewares give the web developer a low-level opportunity to implement all kinds of functionalities by creating a middleware stack of chained Rack-based applications as part of the their application.</li></ul><p>At its core, Rack allows your Ruby application to focus on generating dynamic content and making server-side changes — it takes care of lower-level tasks so you don’t have to think about them.</p><p>This article came from a desire to better understand Sinatra’s source code, and it has led me down a rabbit hole from which I’m excited to emerge. I am a student at Launch School, and much of the higher level content has come from coursework and student content. Below are the numerous additional materials you might be interested in reading.</p><p>A big thank you to Launch School — the staff who make it all possible and the students who are such a pleasure to work with.</p><p>Thank you so much for reading along. Study on!</p><p>Additional Readings:</p><ul><li><a href="https://github.com/rack/rack">Rack source code</a></li><li><a href="https://github.com/rack/rack/blob/master/SPEC.rdoc">Rack SPEC</a></li><li><a href="https://webapps-for-beginners.rubymonstas.org/rack/rack_env.html">env</a></li><li><a href="https://medium.com/launch-school/demystifying-ruby-applications-ruby-application-servers-and-web-servers-c3d0fd415cb3">Demystifying Ruby Applications, Ruby Application Servers, and Web Servers</a> by <a href="https://medium.com/u/a70245d9697f">Wilfred Tannr Allard</a></li><li><a href="https://blog.engineyard.com/understanding-rack-apps-and-middleware">Rack apps and middleware</a></li><li><a href="https://medium.com/quick-code/rack-middleware-vs-rack-application-vs-rack-the-gem-vs-rack-the-architecture-912cd583ed24">Rack middleware vs Rack application vs Rack</a></li><li><a href="https://guides.rubyonrails.org/rails_on_rack.html#inspecting-middleware-stack">Rails and Rack</a></li><li><a href="https://www.digitalocean.com/community/tutorials/a-comparison-of-rack-web-servers-for-ruby-web-applications">Ruby application servers</a></li><li><a href="https://www.justinweiss.com/articles/a-web-server-vs-an-app-server/">Web servers and app servers</a></li><li><a href="https://www.wpbeginner.com/glossary/apache/">Apache</a></li><li><a href="https://www.tutorialspoint.com/ruby/ruby_socket_programming.htm">Sockets</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5dc89e9d89d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rack: Part I]]></title>
            <link>https://aumi9292.medium.com/rack-part-i-6bb268dde211?source=rss-be9d675ac7b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6bb268dde211</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Austin Miller]]></dc:creator>
            <pubDate>Thu, 29 Oct 2020 21:49:29 GMT</pubDate>
            <atom:updated>2020-10-29T21:57:33.688Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*69tq3btS5WuHhQnq" /><figcaption>Photo by <a href="https://unsplash.com/@francesco_ungaro?utm_source=medium&amp;utm_medium=referral">Francesco Ungaro</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>, <a href="https://www.rubydoc.info/gems/rack/Rack/Lobster">Rack Lobster</a></figcaption></figure><h3>Introduction</h3><p>This is the first in a series of two articles. You can find the second article <a href="https://aumi9292.medium.com/rack-part-ii-5dc89e9d89d8">here</a> or at the bottom of the page.</p><p>These two articles focus on the Rack RubyGem — what it is, where it sits in server-side development, what it means for an application to be Rack-based, and what Rack accomplishes for developers and the frameworks they work with behind the scenes. We’ll dig into a little Rack source code and send some really simple responses back to our browser to demonstrate the material.</p><p>The series has been a learning exercise for me, and I hope it serves as a deeper look into Rack for anyone who’s interested. Please do not hesitate to leave a comment here on Medium or reach out to me in Slack on Launch School. I would love to make these articles as accurate and complete as possible, so please don’t hesitate to leave any feedback.</p><p>You may find this material most useful if you have a broad understanding of network communication, procedural and object-oriented programming, and Ruby. You may also find this material useful if you have some experience with a framework like Sinatra or Ruby on Rails, and want to learn about how Rack functions at a lower level. With no further ado, let’s get started!</p><h3>What is Rack?</h3><p><a href="https://rubygems.org/gems/rack/versions/1.6.4">Rack</a> is a RubyGem that provides an interface for your Ruby web application and the <a href="https://www.digitalocean.com/community/tutorials/a-comparison-of-rack-web-servers-for-ruby-web-applications">application server</a> you’re using. Rack-based applications are those that follow a set of specifications established by Rack that allow Rack to work with the application.</p><p>Rack is a generic interface — it facilitates smooth communication between your Rack-based Ruby app (whether it’s a Sinatra app, a Rails app, an app written using a different framework, or an app written in plain Ruby) and the application server you’re working with (whether you’re using WEBrick, Puma, Passenger, Unicorn, Thin, etc.).</p><p>The diagram below is a high level look at what happens server-side after a user initiates a request by typing in a URL or clicking a link in a browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*j7NyRhEhvLR0o34A1Lk8PA.png" /><figcaption>The Rack RubyGem serves as an interface between the application and the application server during the request-response cycle.</figcaption></figure><p>Rack sits between the application server and the application. In the client-server direction, Rack takes plain text HTTP requests and formats them into Ruby data structures that can be more easily used by your Ruby program or framework. In the server-client direction, Rack then takes the return value of your Ruby program and formats it into HTTP-compliant text to be sent back to the client as an HTTP response.</p><p>Rack allows your application to focus on core business logic — making server-side changes and generating dynamic content. It takes care of lower level tasks like handling HTTP requests and responses.</p><p>We can zoom in to the exchange of information between the application and the application server to show Rack’s role as a <em>generic</em> interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*DofQK76mEgR-zLcsDlTpFw.png" /><figcaption>Rack offers support for many servers, and many applications can be Rack-based.</figcaption></figure><p>Rack provides a standardized way for an application and servers to communicate. A Rack-based application could use WEBrick or Puma — without having to make changes to a configuration file.</p><h3>What makes an application Rack-based?</h3><p>An application is considered Rack-based if it adheres to Rack specifications. Namely, an application must define a call method. This method is the heart of a Rack-based application. There are two requirements for the method.</p><ol><li>call must be defined to take one parameter, often called env.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*K9sKdH5x_h23zkzaHSioCA.png" /><figcaption>A Rack app must define a method named call that takes one argument.</figcaption></figure><p>2. call must return an Array object with three items. The three items are a) a String or Integer object that represents a status code, b) a Hash object that holds key-value pairs of content headers and their values, and c) an object that responds to Enumerable#each and holds the body of the response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*IGlXKBcP-c9fXd9I7bpJ4w.png" /><figcaption>This constitutes a minimum viable Rack application</figcaption></figure><p>When call is actually invoked and passed an argument, env will be bound to a Hash object with HTTP headers and other environment variables that relate to the incoming HTTP request. In short, env is a Hash with all the information about an incoming request that you — or the framework that you’re writing your application in — can use. We’ll take a closer look at env shortly.</p><p>The return value of the call method is used to format an HTTP response that will eventually be sent back to the client.</p><p>Finally, Rack needs to know what to run and how to run it. This can be achieved by using a rackup config.ru file or by requiring ‘rack&#39; and invoking Rack::Handler::WEBrick.run in the file like we do below.</p><p>Let’s examine this canonical example of a simple Rack application.</p><pre>require &#39;rack&#39;</pre><pre>class MyApp<br>  def call(env)<br>    [&#39;200&#39;, { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, [&quot;hello world&quot;]]<br>  end<br>end</pre><pre>Rack::Handler::WEBrick.run MyApp.<em>new</em></pre><p>If you’re following along in a code editor, you can copy and paste this code and save your file as myapp.rb. If you’re not sure if you have the rack gem installed on your machine, you can run gem install rack in the command line. (If you’re not sure you have webrick, you can do the same for that gem). Then you can run ruby myapp.rb in the command line.</p><p>This starts a server on port 8080, listening for incoming requests from a client. To send a request, open a browser and type in http://www.localhost:8080. You should see hello world in that tab.</p><p>To quickly demonstrate another example that returns HTML that will be interpreted by the client, below is an example where we change the &quot;Content-Type&quot; to &quot;text/html&quot;, which tells the browser to interpret the body as HTML rather than plain text.</p><pre><em>require</em> &#39;rack&#39;</pre><pre>class MyApp<br>  def call(env)<br>    body = &quot;&lt;h2&gt;Hello in Style!&lt;/h2&gt;&quot;</pre><pre>    [&#39;200&#39;, { &quot;Content-Type&quot; =&gt; &quot;text/html&quot; }, [body]]<br>  end<br>end</pre><pre>Rack::Handler::WEBrick.run MyApp.<em>new</em></pre><p>This time, we initialize a local variable body, assign it to a String object that can be interpreted by the browser as HTML, specify this new type of content to the browser, and return body as the third element in our Array, which will be displayed in the browser.</p><h3>What is env?</h3><p>Let’s take a look at the env request hash by including it as the body of our response to the browser.</p><pre><em>require</em> &#39;rack&#39;</pre><pre>class MyApp<br>  def call(env)<br>    [&#39;200&#39;, { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, [env.to_s]]<br>  end<br>end</pre><pre>Rack::Handler::WEBrick.run MyApp.<em>new</em></pre><p>If you run ruby myapp.rb in the command line and visit www.localhost:8080, you’ll see the contents of env that are available to your Rack-based application. You’ll see information like &quot;PATH_INFO&quot; =&gt; &quot;/&quot;, &quot;QUERY_STRING&quot; =&gt; &quot;&quot;, &quot;REQUEST_METHOD&quot; =&gt; &quot;GET&quot;, and &quot;HTTP_CACHE_CONTROL&quot; =&gt; &quot;max-age=0&quot;. You’ll also see information that Rack appends to the HTTP request, like &quot;rack.version&quot; =&gt; [1, 3], &quot;rack.multithread&quot; =&gt; true, and &quot;rack.url_scheme&quot; =&gt; &quot;http&quot;.</p><p>env is a Hash with key-value pairs of information that comes from the HTTP request, the server, and Rack itself. You can read more about it and see an example <a href="https://webapps-for-beginners.rubymonstas.org/rack/rack_env.html">here</a>. Rack, Rack middleware, and Rack-based frameworks use the information in this Hash to execute logic. The &quot;PATH_INFO&quot; and &quot;REQUEST_METHOD&quot; are generally the most useful pieces of information for you as the developer. &quot;PATH_INFO&quot; shows the path added to the URL after the hostname, which you (or frameworks you use) can use to direct users to certain pages and execute particular logic. You can use the &quot;REQUEST_METHOD&quot; to understand if the user is requesting a server-side change or simply requesting a resource.</p><h3>Next level of abstraction, please</h3><p>Let’s circle back to the first iteration of our simple Rack-based application.</p><pre>require &#39;rack&#39;</pre><pre>class MyApp<br>  def call(env)<br>    [&#39;200&#39;, { &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; }, [&quot;hello world&quot;]]<br>  end<br>end</pre><pre>Rack::Handler::WEBrick.run MyApp.<em>new</em></pre><p>What’s happening in this code snippet? We’re requiring the Rack library. This gives us access to the Rack::Handler::WEBrick::run method that we invoke on the final line of code, as well as all the other classes and modules implemented as part of the Rack gem.</p><p>On the final line, we’re calling ::new on our Rack-based MyApp class we define above. We then invoke Rack::Handler::WEBrick::run and pass in the instance of our class. What’s happening with all of those constants strung together?</p><p>They’re all different classes and modules included in the Rack library. You can peruse the Rack source code <a href="https://github.com/rack/rack/tree/master/lib">here</a>. If we navigate into the /lib/rack/ subdirectory of the Rack Github repo, we’ll see a Handler subdirectory. Let’s check that out, as that’s the second constant used to access this ::run method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L41wXTeCZFyysJrGzOzdRg.png" /></figure><p>Okay … because we’re invoking Rack::Handler::WEBrick::run, let’s jump into the webrick.rb file.</p><p>This file includes webrick and stringio, then carries out a little monkey patching to accomplish out-of-scope tasks, then opens a module Rack, a nested module Rack::Handler, and a nested class Rack::Handler::WEBrick (which inherits from a subclass of the WEBrick class that’s been included and monkey patched up above).</p><p>This matches the chained modules and classes prepended to the ::run class method we invoke in our myapp.rb file! Great — now we can search for our ::run method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*biyqhv9YZP6weaBPcPkeKw.png" /><figcaption>Rack source code <a href="https://github.com/rack/rack/blob/master/lib/rack/handler/webrick.rb">here</a></figcaption></figure><p>We don’t have to search very far. ::run is defined on the first line of the nested Rack::Handler::WEBrick class. It looks like ::run is going to take an app and an optional options Hash object.</p><p>This optional Hash allows us to specify a hostname and a port other than the default development values of localhost and 8080. On lines 27-28, we’re accessing <a href="https://ruby-doc.org/core-2.7.0/ENV.html">ENV</a> (unrelated to env passed to call) to check the environment we’re running this application in to decide what the hostname should be. On lines 30-36, we set a hostname, a port, and lay the groundwork for WEBrick to use HTTPS if that’s been specified in the application.</p><p>On line 38, we initialize @server and assign it to the value of calling ::new on the WEBrick::HTTPServer class. While out of the scope of this article, <a href="https://github.com/ruby/webrick/blob/master/lib/webrick/httpserver.rb">this class</a> opens and closes a socket and handles any connection errors, among other items. Lines 38-42 use the classes and modules defined in the WEBrick gem to do what WEBrick does best — set up an HTTP server.</p><p>In our search for Rack::Handler::WEBrick::run, we discovered how it’s implemented, how Rack sets up a hostname and port, enables support for HTTPS using webrick/https , and even a little about how WEBrick works. We did not look into Rack handlers, though if we did, we’d see that Rack handlers “<a href="https://github.com/rack/rack/blob/master/lib/rack/handler.rb">connect web servers with Rack</a>,” along with a short list of supported web servers.</p><h3>Part 1: Summary</h3><p>To summarize our discussion so far, we’ve talked about how Rack is a RubyGem that operates between a Ruby application and an application server. We’ve talked about Rack-based applications and the required call method, the env hash it takes and the 3-item Array it must return. We’ve also managed to send a response from our application to the browser.</p><p>Finally, we were able to peer down another level of abstraction into Rack source code to start getting an idea about what we’re doing — and really, what Rack, WEBrick, and other servers that Rack can handle are accomplishing behind the scenes. But — Rack does so much more. In the second article, we’ll examine how we can use Rack to stack multiple modular applications on top of each other.</p><p>Continue reading: <a href="https://aumi9292.medium.com/rack-part-ii-5dc89e9d89d8">Rack: Part II</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6bb268dde211" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 2: The big picture of OOP]]></title>
            <link>https://aumi9292.medium.com/part-2-the-big-picture-of-oop-469a6c32c8a9?source=rss-be9d675ac7b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/469a6c32c8a9</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[launch-school]]></category>
            <category><![CDATA[oop]]></category>
            <dc:creator><![CDATA[Austin Miller]]></dc:creator>
            <pubDate>Fri, 04 Sep 2020 00:49:49 GMT</pubDate>
            <atom:updated>2020-09-04T02:45:59.571Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HubyJifgJeK_qvse" /><figcaption>Photo by <a href="https://unsplash.com/@ddealmeida?utm_source=medium&amp;utm_medium=referral">Dan DeAlmeida</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This is the second in a series of two articles that provide an introduction about what object oriented programming (OOP) is. In the first article, we discussed classes, objects, attributes, behaviors, instance variables, and instance methods.</p><p>We also created a Book class and instantiated a few Book objects that will be referenced in this article. You can read the first article <a href="https://medium.com/@aumi9292/part-1-an-intro-to-oop-d95aa6e445ce">here</a>.</p><h3>The four pillars of OOP</h3><p>OOP famously has four pillars — four major concepts that justify the existence of this style of programming and act as guidelines for programmers as they code in an OOP fashion.</p><h3>Abstraction</h3><p>Abstraction means to simplify complexity. Take our pages= setter method. The user does not need to know that an if-else conditional is used to check their input, or that Object#instance_of? is used to do so. They can call the setter method and use its functionality. Going even deeper, when we call an instance method on an object, like Object#instance_of? on an Integer object — we don’t need to know how that method works internally. We can simply rest assured that Ruby will return true or false based on the calling object and the passed in argument.</p><p>Abstraction is the idea that defining classes and grouping behaviors and attributes within them allows users to work with objects made from those classes without having to get bogged down in implementation details that someone else has already taken the time to understand and approach.</p><p>Abstraction allows programmers to work at new levels of a problem. For example — with a Book class written and ready to go, another programmer might begin work on a Library class that interacts with Book objects in some way. The programmer working with the Library class might not know every detail of the Book class, because they don’t need to.</p><p>One metaphor that comes to mind for abstraction is the idea of a heart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tBQGHDOPAxKNuGAb" /><figcaption>Photo by <a href="https://unsplash.com/@nicolafioravanti?utm_source=medium&amp;utm_medium=referral">Nicola Fioravanti</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This is an abstraction of a heart. A heart does not look like this. But it’s a simple, effective way of communicating about this complex organ that we cannot see.</p><h3>Encapsulation</h3><p>Encapsulation boils down to two fundamental principles — protecting data and grouping data and methods together.</p><p>Encapsulation is a form of <strong>data protection</strong>. We can expose only the data and functionalities that we want users to have. In our Book class, we allow read and write access for @pages while we only allow read access for @title and author. We determine what a user can see and do with an object. Additionally, we can even use methods ( Module#public, private, and protected ) within our classes to determine what methods we want to be available to be called on objects outside of the class definition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*snvLeNLb8sYplmo2" /><figcaption>Photo by <a href="https://unsplash.com/@shs521?utm_source=medium&amp;utm_medium=referral">Susan Holt Simpson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Encapsulation is also the idea of <strong>grouping data and functionalities together</strong>. In the context of our Book class, we group a set of attributes and behaviors that will be available for each object we instantiate from the Book class. There are many levels of encapsulation within OOP. Series of instructions are grouped together in methods. Bundles of data are grouped together in objects. Methods and data are grouped together in classes.</p><p>Modules, which are similar to classes with the exception that the ::new method cannot be called on them, are a sort of toolbox. They act as containers , or <em>namespaces</em>, for classes, constants, and methods. Modules can be <em>included</em> in a class to give classes access to additional functionalities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q972Hh4hPK_hbfE7" /><figcaption>A purse is kind of like a module.</figcaption></figure><h3>Inheritance</h3><p>Inheritance is the concept that classes can inherit behaviors and attributes from other classes and modules. It is the idea of categorizing relationships and hierarchies between classes.</p><p>It’s something that’s so natural for humans to do. For example, I’m looking at a laptop screen right now, so let’s work with that.</p><p>Let’s say that my laptop, austins_laptop, is an instance of a Laptop class, which is a type of Computer. You could say that Laptop is a subclass of the Computer class.</p><p>In other words, the Laptop class inherits from the Computer class, which might inherit from an Electronics class, which might inherit from a Machine class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xK1Kit_1Pa7UmFre" /><figcaption>Computers, phones, headphones, and watches are all types of machines.</figcaption></figure><p>In Ruby, all classes inherit from classes and modules until they reach the primordial BasicObject. Inheritance signifies the order in which Ruby will search different containers for the methods that you call. If Ruby finds the method, it will stop searching and use it. If it doesn’t it will keep searching until there is nowhere else to look and return a NoMethodError.</p><p>For example, if you have an Array object and call not_a_real_method on it, Ruby will first look in Array, then Enumerable, then Object, then Kernel, then BasicObject and then return a NoMethodError. You can always find the order that Ruby will search for methods (known as the method lookup chain or method lookup path) by calling the class method ::ancestors on the class in question.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*Tc-fnMszIM2dan0SBSY9ww.png" /></figure><p>Ruby is a single inheritance language, which means that a class can only directly inherit from one superclass (while modules can be mixed into classes to provide additional functionality). Ruby allows for class inheritance and interface inheritance. Both Enumerable and Kernel are examples of modules. Enumerable is mixed in to the Array class, while Kernel is mixed in to the Object class.</p><p>Let’s take a step back and re-examine our Book class we defined in the first article.</p><pre>class Book<br>  def initialize(title, author, pages)<br>    @title = title <br>    @author = author<br>    @pages = pages<br>  end</pre><pre>def title<br>    @title<br>  end</pre><pre>def author<br>    @author<br>  end</pre><pre>def pages<br>    @pages<br>  end</pre><pre>def pages=(new_pages)<br>    if new_pages.instance_of?(Integer)<br>      @pages = new_pages<br>    else <br>      puts &#39;Sorry, please enter a number&#39;<br>    end <br>  end<br>end</pre><p>Let’s create a class that inherits from Book.</p><pre>class Novella &lt; Book; end</pre><p>We can instantiate a Novella object the same way we instantiate a Book object. Novella inherits all the methods defined in the Book class, including the initialize method.</p><pre>sad_story = Novella.new(&#39;Flowers for Algernon&#39;, &#39;Daniel Keyes&#39;, 23)</pre><p>All the behaviors available for Book objects are now available for the object bound to sad_story, despite the emptiness of Novella. Subclasses can either override or extend the functionalities available in superclasses. Let’s extend the functionalities of our Novella class.</p><pre>class Novella &lt; Book<br>  def binge_read<br>    puts &quot;I read it all in one night!&quot;<br>  end<br>end</pre><p>With binge_read, we now have an available action we can take on Novella objects that we cannot use with Book objects. We have defined more specific behaviors for our subclass. Let’s define one more class and give it some unique functionality before we move on.</p><pre>class Dictionary &lt; Book <br>  def learn_new_word<br>    puts [&#39;tenable&#39;, &#39;crepuscular&#39;, &#39;petrichor&#39;].sample<br>  end <br>end</pre><p>Then we can create a Dictionary object.</p><pre>websters = Dictionary.new(&#39;1978 Edition&#39;, &#39;Webster Team&#39;, 14_542)</pre><p>We now have two classes, Novella and Dictionary, that inherit from the superclass Book. Both novellas and dictionaries are types of books that have authors, page numbers, and titles. However, in this example, we cannot learn a new word from a Novella object, nor can we binge_read a dictionary object. These specific behaviors are only available for the particular subclasses for which they are relevant.</p><p>Inheritance helps programmers re-use their code when needed and extract common, repeated code between classes and move it to a superclass. Rather than re-write the Book getter and setter methods for the Novella and Dictionary classes, we can simply have the two classes inherit from the Book class.</p><p>Additionally, inheritance allows programmers to extend or override the behaviors of superclasses within subclasses.</p><h3>Polymorphism</h3><p>Polymorphism simply refers to the fact that methods defined in one class can be defined differently in different classes. A method binge_read can output &#39;I read it all in one night!&#39; to the screen for Novella objects, and have a slightly different or even completely different implementation in another class. Let’s define a binge_read method in the Dictionary class.</p><pre>class Dictionary &lt; Book <br>  def learn_new_word<br>    puts [&#39;tenable&#39;, &#39;crepuscular&#39;, &#39;petrichor&#39;].sample<br>  end<br>  <br>  def binge_read<br>    puts &quot;Zzzzzzzz&quot;<br>  end <br>end</pre><p>Our Dictionary#binge_read method has a different implementation than our Novella#binge_read method. We can call binge_read on objects made from both of these classes, and the return values of each call will be different.</p><pre>[sad_story, websters].each { |book| book.binge_read }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*XO2UsUxGNRZFq8vDvr4j1g.png" /></figure><p>Methods with the same name can be defined in unrelated classes or overridden in a subclass to have a different implementation than a superclass.</p><h3>The benefits of OOP</h3><p>We’ve talked through some of the most basic ideas of OOP. We defined a few classes with some limited behaviors and attributes. We instantiated a few objects, each with their own unique instance variables, and we talked through some of the fundamental principles of the OOP paradigm. There is so much more, but we must save it for another time. Before we leave, let’s talk through some of the benefits of OOP.</p><h4>Concrete thinking</h4><p>OOP allows programmers to think in terms of concrete nouns and verbs. Representing seemingly opaque, intangible digital items, like a database or the internet, is much more accessible when you can use clear, concise terms to do so.</p><h4>New levels of abstraction</h4><p>OOP allows programmers to abstract away solutions to complex problems. Rather than trying to hold all aspects of a problem in your head at once, you can approach chunks of the problem one step at a time. As you solve more and more problems, you can forget implementation details you used to solve one problem and focus on tackling the next, even more complex problem.</p><h4>Reduced Dependencies</h4><p>Using classes and modules to modularize code into containers makes for programs that have fewer dependencies and are therefore easier to maintain than a program made of 1,000 lines that could fail if one typo were introduced or if one local variable escaped its intended scope.</p><h4>Flexible code</h4><p>Compartmentalized classes and modules can be re-used for different programs. One module of code that was used for a program could easily be tweaked or directly re-used for another program.</p><h4>DRYer code</h4><p>Inheritance allows programmers to extract common code between multiple classes, place it in a superclass, and have subclasses inherit from the superclass. This helps achieve one of the fundamental principles of clean code — Don’t Repeat Yourself.</p><h4>Better-organized code</h4><p>While organizing code into modules and classes does not result in shorter programs, it results in more clearly organized ones. Classes, methods, and constants can all be placed in well-named modules. This helps avoid name clashing errors and help programmers understand relationships between various classes and objects instantiated from those classes.</p><h3>In conclusion</h3><p>Thank you for taking the time to read this article. It has been my attempt to summarize the very very basic fundamentals of OOP. Numerous important topics ( attr_* methods, the self keyword, Ruby’s fake operators and syntactic sugar, commonly overridden methods like to_s, working with collaborator objects, and lexical scope, to name a few) were outside the scope of this article.</p><p>I hope that you have found this useful in some way. If you have any questions about OOP or programming in general, or any feedback or suggestions, please feel free to leave a comment. If you’re a Launch School student, please feel free to reach out to me directly in Slack.</p><p>Additionally — a huge thank you to inspiring fellow Launch School student <a href="https://medium.com/u/937c1e242fcc">Leena</a> and esteemed Launch School instructor <a href="https://medium.com/u/3912e37916c3">*superchilled</a> for both reading through these articles and providing immensely valuable constructive feedback.</p><h4>Thank you.</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=469a6c32c8a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 1: An Intro to OOP]]></title>
            <link>https://aumi9292.medium.com/part-1-an-intro-to-oop-d95aa6e445ce?source=rss-be9d675ac7b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/d95aa6e445ce</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[launch-school]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Austin Miller]]></dc:creator>
            <pubDate>Fri, 04 Sep 2020 00:49:04 GMT</pubDate>
            <atom:updated>2020-09-07T15:32:28.725Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*D2Fl1Gukoe3TF3_Sw8CsHw.png" /></figure><p>Object oriented programming (OOP) is a programming paradigm. It allows us to represent the complexities of the real, physical world in a digital way. Languages that support some level of object-orientation are ubiquitous — they include Ruby, Python, Javascript, PHP, C++, C #, Java, Rust, Kotlin, Go, and many others.</p><p>This is the first article in a two-part series that will approach the topic of OOP using Ruby to illustrate ideas and is intended for those who have an understanding of the fundamentals of procedural programming and are learning OOP.</p><p>At its core, OOP consists of classes and objects made from those classes.</p><h3>Classes determine attributes and behaviors</h3><p>A class is a blueprint or a template for objects. It is the <em>concept </em>or <em>idea </em>of a thing, while an object is one physical manifestation of that concept. For example, take the concept of a book. Picture one in your mind. What do you see? In other words, what makes a book a book?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sEIoBAAxNzF_3NXU" /><figcaption>Photo by <a href="https://unsplash.com/@asteriskyg?utm_source=medium&amp;utm_medium=referral">ASTERISK</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>A book has attributes</strong></p><ul><li>Some potentially captivating title</li><li>Some author/s who wrote it</li><li>Some number of pages</li><li>Some type of paperback or hardcover binding</li><li>A cover that is some color</li><li>Some measurable weight</li></ul><p>These are all characteristics — they describe the book. <em>Instance variables</em> are the attributes that an individual book has (e.g., a title of <em>Harry Potter and the Chamber of Secrets</em>, a page number of <em>432,</em> a weight of <em>0.74 lbs). </em>The total amalgamation of all instance variables an individual book has make up that particular book’s state.</p><p><strong>Specific actions can be done with a book</strong></p><ul><li>It can be read</li><li>It can be picked up</li><li>It can be put down</li><li>It can be thrown</li><li>Pages can be ripped out</li><li>Notes can be written in the margins</li></ul><p>In OOP, the actions that you can do with an object are defined in the class definition. They are called <em>instance methods</em>, and can be called on any object made from the class.</p><p>Taking a step back, a class dictates the possible attributes or characteristics of objects that are made from it.</p><p>Let’s focus on three key attributes — the title, author, and number of pages to create a Book class below.</p><pre>class Book<br>  def initialize(title, author, pages)<br>    @title = title <br>    @author = author<br>    @pages = pages<br>  end <br>end</pre><p>Within our simple Book class definition is a special instance method initialize. This is Ruby’s constructor method. It is triggered every time the class method ::new is called on the Book class. Note that initialize is a <em>private</em> instance method, which means it cannot be called outside of a class definition. Additionally, if the initialize method is defined to take parameters, the ::new method must be passed arguments (unless the parameters defined within the class definition are given default parameters).</p><h3>Instance variables compose state</h3><p>You may have noticed the variables prefixed with @ . Instance variables are denoted with the @ sign (also known as the sigil). These variables are scoped at the object level — they are available to all instance methods defined within a class, and each object made from a class has its own copy of the variable that can hold its own value.</p><p>With our class defined, we can call new directly on the class, feeding it the information we want to use to create the initial state of the object.</p><pre>Book.new(&#39;Triumph of the City&#39;, &#39;David Glaeser&#39;, 338)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CpfVvXAsXegUFrXw" /><figcaption>Photo by <a href="https://unsplash.com/@almosbech?utm_source=medium&amp;utm_medium=referral">Almos Bechtold</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We have created, or <em>instantiated </em>one Book object — one <em>instance</em> of the Book class. This book has a bundle of instance variables — @title, @author, and @pages. The instance variables of this particular instance of the class are bound to the values we pass to the ::new method invocation. In other words, this Book object has a unique state that is made up of all the objects bound to its instance variables.</p><p>We can also assign this object to a local variable for safekeeping.</p><pre>triumph_of_the_city = Book.new(&#39;Triumph of the City&#39;, &#39;David Glaeser&#39;, 338)</pre><p>How can we access data stored within an object? How can we find the number of pages in our Book object? Right now — our options are limited. If you’re interested in gaining a deeper knowledge of Ruby’s meta-programming, look into Object#instance_variables and Object#instance_variable_get.</p><p>As a general rule of thumb, we cannot directly access an object’s instance variables outside of the class definition — they are private and only accessible within the scope of the object. However, we can define instance methods within the class definition and reference instance variables there. These methods can then be called on an object of that class to access and interact with that object’s instance variables.</p><pre>class Book<br>  def initialize(title, author, pages)<br>    @title = title <br>    @author = author<br>    @pages = pages<br>  end</pre><pre>def title<br>    @title<br>  end<br>end</pre><p>Here, we’ve added an instance method title, in which we access the instance variable @title. Because this method is available to all Book objects, we can call title like so.</p><pre>triumph_of_the_city.title</pre><p>This returns the title of the book.</p><p>Instance methods that access instance variables are called <em>getter</em> methods, and those that allow a person to modify instance variables are called <em>setter </em>methods. Let’s write a few more getters and a setter method.</p><pre>class Book<br>  def initialize(title, author, pages)<br>    @title = title <br>    @author = author<br>    @pages = pages<br>  end</pre><pre>def title<br>    @title<br>  end</pre><pre>def author<br>    @author<br>  end</pre><pre>def pages<br>    @pages<br>  end</pre><pre>def pages=(new_pages)<br>    @pages = new_pages<br>  end <br>end</pre><p>As you can see, we now have getter methods for title, author, and pages. We also have a setter method for pages. This one might seem strange. It’s a Ruby convention to use = at the end of the name of a setter method. It’s similar to predicate methods ending with ?.</p><p>The setter takes one argument, the new value that the user wants to assign to the instance variable. With Ruby’s syntactic sugar, calling a setter method on an object outside of the class definition is a breeze! Let’s say we rip one of the pages out of our book.</p><pre>triumph_of_the_city.pages = 337</pre><p>Ruby allows the act of setting an instance variable of an object to look like assignment. Without the sugar, using the setter method looks like the code below.</p><pre>triumph_of_the_city.pages=(337)</pre><p>The syntax may take a little while to get used to, but let’s summarize everything we’ve done so far.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*k0JuJdnPE0mG-xdH" /><figcaption>Photo by <a href="https://unsplash.com/@kaleidico?utm_source=medium&amp;utm_medium=referral">Kaleidico</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><ul><li>We defined a class. This class is the template for all objects that are instantiated from it. In the class we dictate the possible attributes and the possible behaviors that objects made from that class will have.</li><li>We instantiated a Book object and gave it some unique values for instance variables.</li><li>We defined a handful of getter methods to access the instance variables by calling a method on objects outside of the class definition.</li><li>We defined a setter method we can use to re-assign the instance variable pages to a new value.</li></ul><p>Let’s create one more Book object and bind it to a local variable.</p><pre>walkable_city = Book.new(&#39;Walkable City Rules&#39;, &#39;Jeff Speck&#39;, 290)</pre><p>We now have two different instances of the Book class. They have different titles, authors, and numbers of pages. In other words, they are two different Book objects that each have a distinct <em>state</em>.</p><p>*We will forego talking about attr_* methods — Ruby’s short-hand option for creating getters and setters — in this article.</p><h3>Instance methods give functionality</h3><p>Right now, we have two Book objects. We can create a new book by passing arguments into the ::new method call on the Book class. Let’s think about the functionalities available for any Book objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JiRPb5V4t_q2KMS7" /><figcaption>Photo by <a href="https://unsplash.com/@joannakosinska?utm_source=medium&amp;utm_medium=referral">Joanna Kosinska</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Because we wrote getter instance methods for title, author, and pages we can access the values of each of these instance variables from outside the class. We also wrote a setter method for pages, which allows us to change the value bound to @pages in any Book object to any value we desire. We have read and write access for the pages instance variable, while we have read-only access to title and author.</p><p>With our setter method for @pages, we can alter the number of pages. In fact, a user of our program can even set the number of pages to a String object of &#39;hello&#39;.</p><pre>walkable_city.pages = &#39;hello&#39;</pre><p>Assigning a String to a variable that is intended to represent a number of pages in a book is nonsensical. Let’s put some restrictions on what a user can do with the @pages instance variable. Rather than allowing a user to set the value to anything they please, let’s only allow them to choose an Integer object.</p><pre>def pages=(new_pages)<br>  if new_pages.instance_of?(Integer)<br>    @pages = new_pages<br>  else <br>    puts &#39;Sorry, please enter a number&#39;<br>  end <br>end</pre><p>We use a simple if-else conditional that calls Object#instance_of? on the object bound to the passed in parameter new_pages. To the instance_of? call, we pass in the argument of the class name Integer. This is a predicate method that will return true or false, depending whether the class of the calling object matches the passed in argument. If new_pages is bound to anInteger object, we point the instance variable @pages to that Integer. If the user tries to pass in any other type of object, like a String or a Hash, we output an error message to the terminal and do not assign any value to @pages.</p><p>We have effectively put one protective measure in place to ensure that @pages will always point to an Integer object. This makes for a more robust program. If we have another instance method that makes use of @pages, we can rest a little more assured that we can expect an Integer and not an object from some other class. This will keep our program from breaking.</p><p>Now that we have a small, functioning Book class, a couple Book objects with their own unique instance variables and a shared set of methods (just the getters and setter), we can take a look at the main ideas of OOP and its main benefits as a programming paradigm in the second article of this series <a href="https://medium.com/@aumi9292/part-2-the-big-picture-of-oop-469a6c32c8a9">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OYcQPFKY4eHWrOa5" /><figcaption>Photo by <a href="https://unsplash.com/@sunnystate?utm_source=medium&amp;utm_medium=referral">Reuben Juarez</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d95aa6e445ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Starting @ Launch School: June 2020]]></title>
            <link>https://aumi9292.medium.com/starting-launch-school-june-2020-a40a94992a45?source=rss-be9d675ac7b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a40a94992a45</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[launch-school]]></category>
            <dc:creator><![CDATA[Austin Miller]]></dc:creator>
            <pubDate>Fri, 26 Jun 2020 20:28:12 GMT</pubDate>
            <atom:updated>2020-06-26T20:28:12.614Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m writing this brief note as a personal introduction from me to you. TLDR: I’m a Denver-based market researcher turned software engineering student &amp; aspiring web developer. Nice to meet you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mUybCLzBedznlnRm" /><figcaption>Photo by <a href="https://unsplash.com/@drew_beamer?utm_source=medium&amp;utm_medium=referral">Drew Beamer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I type this introduction to you from my desk, located in the Hale neighborhood of Denver, Colorado. Scattered around on this glossy Ikea-esque desk are monitors, whiteboards, notecards, notebooks, and a collection of coding books checked out from the library right before the world and all of its cultural institutions shut down.</p><p>Oh — and a slinky, a few pyrite cubes, and some rubber bands. I highly enjoy desk trinkets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1zBGhHF0p4Mb0-yj" /><figcaption>(This is a desk trinket I’d like) Photo by <a href="https://unsplash.com/@hautier?utm_source=medium&amp;utm_medium=referral">Christophe Hautier</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Since March of 2020, I’ve been slowly and surely learning about computers, software, web development, and programming. In these brief and globally tumultuous few months, I’ve switched from attending a bootcamp in Denver to teaching myself using online and print materials to finally discovering Launch School. I’ve spent a month doing Launch’s prep work and another month going through the first of twelve modules. My plan is to use the next one to three weeks to study for the first assessment, AKA RB109.</p><p>Like so many others, I’ve come to software engineering via a non-linear path. I studied linguistics, French, and communication before moving to Hangzhou, China, and teaching English for a year. I returned to Denver and have worked in market research and in research and evaluation for the last four years.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*D1c0R7PQjXwXF_te" /><figcaption>(This is very close to where I live, though I don’t have this view) Photo by <a href="https://unsplash.com/@theadventurebitch?utm_source=medium&amp;utm_medium=referral">Cassie Gallegos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I plan to become a backend developer after completing Launch School. The world of software engineering is so vast and so burgeoning that it does and will continue to prompt revolutionary breakthroughs in a wide range of human endeavors. I would love to be a part of that. I’m deeply interested in human interaction, equity, sustainability, futurism, urban planning, walkability, maps, data visualization, linguistics, natural language processing, storytelling with data, virtual reality, augmented reality, and IoT.</p><p>I plan to use this platform to document my process in Launch School and the process of becoming a web developer during the time of COVID-19. As I continue through the program, I’ll add to this online journal, whether technical or philosophical in nature:</p><ol><li>Epiphanies and realizations</li><li>Challenges and successes</li><li>Enticing tidbits and miscellany</li></ol><p>Please feel free to reach out if you are going through this process yourself, if you have any questions from one beginner to another, or if you have any words of wisdom you’d like to share.</p><p>Thank you for reading this informal introduction. I look forward to continuing on the slow and steady path of mastery, and I hope you’ll pop in again. I also hope you and your loved ones and your communities are staying safe during the global pandemic and international civil rights movement.</p><p>Warmly,</p><p>Austin</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a40a94992a45" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>