<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>exercism on Andrés Álvarez</title>
    <link>https://aalvrz.me/tags/exercism/</link>
    <description>Recent content in exercism on Andrés Álvarez</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 12 Jun 2017 00:00:00 +0000</lastBuildDate>
    
	<atom:link href="https://aalvrz.me/tags/exercism/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Using Lambdas in Case Statements in Ruby</title>
      <link>https://aalvrz.me/posts/using-lambdas-in-case-statements-in-ruby/</link>
      <pubDate>Mon, 12 Jun 2017 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/using-lambdas-in-case-statements-in-ruby/</guid>
      <description>&lt;p&gt;In a &lt;a href=&#34;http://aalvarez.me/blog/posts/using-objects-and-ranges-with-cases-in-ruby.html&#34;&gt;previous post&lt;/a&gt; I talked about how we could use Ruby ranges inside case statements. This was a very neat way of using case statements that would make our code more readable and less repetitive.&lt;/p&gt;
&lt;p&gt;The other day I was trying to solve the &lt;a href=&#34;http://exercism.io/submissions/03c3c93f23b8420faff3107e2ad18286&#34;&gt;Bob Ruby exercise in Exercism&lt;/a&gt;, and I came up with another very cool way to use case statements: with Lambdas.&lt;/p&gt;
&lt;h2 id=&#34;the-problem&#34;&gt;The Problem&lt;/h2&gt;
&lt;p&gt;The Bob problem is very simple. The program receives some input, and it returns some output based on the contents of the input. A strong indication for using a case statement. From the problem&#39;s README file:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Bob is a lackadaisical teenager. In conversation, his responses are very limited.

Bob answers &#39;Sure.&#39; if you ask him a question.

He answers &#39;Whoa, chill out!&#39; if you yell at him.

He says &#39;Fine. Be that way!&#39; if you address him without actually saying anything.

He answers &#39;Whatever.&#39; to anything else.
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;solutions&#34;&gt;Solutions&lt;/h2&gt;
&lt;p&gt;The test provided by Exercism indicates that we should create a &lt;code&gt;Bob&lt;/code&gt; class with a &lt;code&gt;hey&lt;/code&gt; class method that receives a remark. We could then use a case statement with this remark and evaluate if the remark is a question, yelling, or whatever else needs to be determined according to the instructions. We could create some class methods to determine each of these possibilities:&lt;/p&gt;</description>
    </item>
    
  </channel>
</rss>