<?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 Athira Ramanan on Medium]]></title>
        <description><![CDATA[Stories by Athira Ramanan on Medium]]></description>
        <link>https://medium.com/@athiraramanan29?source=rss-55e510d6187b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Athira Ramanan on Medium</title>
            <link>https://medium.com/@athiraramanan29?source=rss-55e510d6187b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 16:39:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@athiraramanan29/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[Why AI + Ruby on Rails Is the Perfect Combination for Rapid Intelligent App Development]]></title>
            <link>https://medium.com/@athiraramanan29/why-ai-ruby-on-rails-is-the-perfect-combination-for-rapid-intelligent-app-development-bcf2739416c7?source=rss-55e510d6187b------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcf2739416c7</guid>
            <dc:creator><![CDATA[Athira Ramanan]]></dc:creator>
            <pubDate>Thu, 08 Jan 2026 16:31:48 GMT</pubDate>
            <atom:updated>2026-01-08T16:31:48.026Z</atom:updated>
            <content:encoded><![CDATA[<p>Modern applications are no longer just CRUD interfaces.<br>Users expect <strong><em>search that understands intent</em></strong>, <strong><em>chatbots that assist</em></strong>, and <strong><em>systems that automate decisions</em></strong>.</p><p>Most Rails apps start the same way:</p><p>A few models, Some controllers, Basic search, Manual workflows ….</p><p>And then product asks:</p><p>Can we add a chatbot?<br>Can search understand meaning?<br>Can we auto-generate this content?</p><p>The good news?<br>You don’t need to abandon Ruby on Rails to build these features.</p><p>Rails + AI is one of the <strong>fastest ways to ship intelligent applications today</strong>.</p><p>In this article, we’ll explore:</p><ul><li><strong>Why AI fits naturally into Rails</strong></li><li><strong>The most popular AI services you can use</strong></li><li><strong>The key AI capabilities you can add to Rails apps <em>right now</em></strong></li></ul><h3>Why AI + Ruby on Rails Works So Well</h3><p>Ruby on Rails has always been about <strong>developer productivity</strong>.</p><p>AI APIs today share the same philosophy.</p><h3>🚀 Rails Strengths That Match AI Perfectly</h3><ul><li>Convention over configuration</li><li>Clean MVC architecture</li><li>Background jobs &amp; service objects</li><li>Rapid iteration</li></ul><h3>🤖 AI APIs Are Just HTTP Calls</h3><p>Modern AI services:</p><ul><li>Are stateless</li><li>Use REST APIs</li><li>Return structured JSON</li><li>Require no ML infrastructure</li></ul><p>This means: <strong><em>AI fits naturally as a service layer inside Rails</em></strong></p><p>You can:</p><ul><li>Wrap AI logic in service objects</li><li>Control cost and rate limits</li><li>Ship AI features in days, not months</li></ul><h3>Popular AI Services You Can Use with Rails</h3><p>Let’s look at the most commonly used AI platforms and where they shine.</p><h3>OpenAI</h3><p><strong>Best for:</strong> General-purpose AI</p><ul><li>Text generation (GPT models)</li><li>Embeddings for semantic search</li><li>Chatbots</li><li>Excellent Ruby SDK support</li></ul><p><strong>Rails use cases:</strong></p><ul><li>Customer support bots</li><li>AI-powered search</li><li>Auto-generated content</li></ul><h3>Google Gemini</h3><p><strong>Best for:</strong> Multimodal AI</p><ul><li>Text, image, and video understanding</li><li>Strong integration with Google ecosystem</li></ul><p><strong>Rails use cases:</strong></p><ul><li>Image + text analysis</li><li>AI assistants with visual context</li></ul><h3>Hugging Face</h3><p><strong>Best for:</strong> Open-source &amp; self-hosted AI</p><ul><li>Thousands of open models</li><li>Full control over infrastructure</li><li>Privacy-friendly</li></ul><p><strong>Rails use cases:</strong></p><ul><li>On-premise AI</li><li>Cost-sensitive workloads</li><li>Custom fine-tuned models</li></ul><h3>Key AI Capabilities You Can Add to Rails Apps Today</h3><p>These are <strong>real, production-ready features</strong> Rails teams are already shipping.</p><h3>1. Natural Language Processing (NLP)</h3><p>AI makes text-based features dramatically more powerful.</p><p><strong>Examples:</strong></p><ul><li>Text summarization (tickets, emails, reports)</li><li>Sentiment analysis for feedback</li><li>Auto-generated blog posts or descriptions</li><li>Classification and tagging</li></ul><p><strong>Rails pattern:</strong></p><p>Controller → AI Service → Prompt → Response</p><h3>2. AI-Powered Search</h3><p>Traditional keyword search is no longer enough.</p><p><strong>AI search enables:</strong></p><ul><li>Semantic search using embeddings</li><li>Results based on meaning, not keywords</li><li>Personalised search experiences</li></ul><p><strong>Typical stack:</strong></p><ul><li>Rails</li><li>Embeddings (OpenAI / Hugging Face)</li><li>Vector DB (pgvector, Pinecone, Qdrant)</li></ul><h3>3. Chatbots &amp; Q&amp;A Systems</h3><p>Chatbots are no longer just for support.</p><p><strong>Use cases:</strong></p><ul><li>Product onboarding bots</li><li>Internal knowledge assistants</li><li>Context-aware Q&amp;A systems</li></ul><p>With Rails:</p><ul><li>Store conversation context</li><li>Control responses</li><li>Add guardrails easily</li></ul><h3>4. Predictive &amp; Intelligent Features</h3><p>AI can help apps <em>anticipate</em> user needs.</p><p><strong>Examples:</strong></p><ul><li>Demand forecasting</li><li>Recommendations</li><li>Fraud detection</li><li>User behaviour scoring</li></ul><p>Rails handles orchestration; AI handles intelligence.</p><h3>Best Practices When Adding AI to Rails</h3><ul><li>Use service objects for AI logic</li><li>Never trust AI output blindly</li><li>Cache responses when possible</li><li>Monitor token usage and cost</li><li>Keep prompts versioned and testable</li></ul><blockquote>AI doesn’t replace Ruby on Rails.It <strong>extends it</strong>.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcf2739416c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a Generic Web Scraper with Scrapy — Extract Titles, Meta, Headers, and Text Content]]></title>
            <link>https://medium.com/@athiraramanan29/how-to-build-a-generic-web-scraper-with-scrapy-extract-titles-meta-headers-and-text-content-4395021b3da9?source=rss-55e510d6187b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4395021b3da9</guid>
            <dc:creator><![CDATA[Athira Ramanan]]></dc:creator>
            <pubDate>Sun, 08 Jun 2025 05:09:19 GMT</pubDate>
            <atom:updated>2025-06-08T05:09:19.814Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Build a Generic Web Scraper with Scrapy — Extract Titles, Meta, Headers, and Text Content</h3><p>Web scraping in Python is an automated method for extracting data from websites. It involves using scripts to fetch HTML content, parse it, and then extract the desired information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vEr1h88EogC98QG4qlQy-A.png" /></figure><p><strong>In this tutorial, we’ll build a generic Scrapy spider that extracts:</strong></p><ol><li>Page titles</li><li>Meta descriptions</li><li>All headers (h1, h2, h3)</li><li>Page URLs</li><li>Main text content</li></ol><blockquote>You can customize this to scrape any website and collect structured page data.</blockquote><h4>Step 1: Setup Scrapy Project</h4><p>First, install Scrapy if you haven’t already:</p><pre>pip install scrapy</pre><p>Then create your project:</p><pre>scrapy startproject bookscraper<br>cd bookscraper</pre><blockquote>This creates a folder structure with everything needed to run spiders.</blockquote><h4>Step 2: Write a Book Spider</h4><p>A <strong>spider</strong> is a class you write in Scrapy that defines <strong>how to crawl a website and extract data</strong> from it.</p><p>It tells Scrapy:</p><ul><li><strong>Where to start crawling</strong> (the URLs)</li><li><strong>What pages to visit next</strong> (following links)</li><li><strong>What information to extract</strong> from the pages</li></ul><p>You can think of a spider as the “brain” of your scraper.</p><p><strong><em>Create a spider file inside bookscraper/spiders/ called book_spider.py:</em></strong></p><pre># 1. Spider Setup<br>class BooksSpider(scrapy.Spider):<br>    name = &quot;books&quot;<br>    allowed_domains = [&quot;books.toscrape.com&quot;]<br>    start_urls = [&quot;https://books.toscrape.com/&quot;]</pre><ul><li>name: Unique identifier for this spider.</li><li>allowed_domains: Limits crawling to this domain only (prevents leaving the target site).</li><li>start_urls: The first URL(s) to start scraping from.</li></ul><pre># 1. Parse Homepage — Extract Categories<br>def parse(self, response):<br>    categories = response.css(&quot;div.side_categories ul li ul li a&quot;)<br>    for category in categories:<br>        category_name = category.xpath(&quot;text()&quot;).get().strip()<br>        category_url = response.urljoin(category.attrib[&#39;href&#39;])<br>        yield scrapy.Request(<br>            url=category_url,<br>            callback=self.parse_category,<br>            meta={&#39;category&#39;: category_name}<br>        )</pre><ul><li>Extracts all book category links from the sidebar.</li></ul><p><strong><em>For each category:</em></strong></p><ul><li>Extracts the category name.</li><li>Creates the full URL (category_url) using response.urljoin.</li><li>Sends a new request to the category page.</li><li>Passes the category name in meta so later methods know the category.</li></ul><pre>#Parse Each Category — List Books &amp; Pagination<br>def parse_category(self, response):<br>    category = response.meta[&#39;category&#39;]<br>    books = response.css(&quot;article.product_pod&quot;)<br><br>    for book in books:<br>        book_url = response.urljoin(book.css(&quot;h3 a::attr(href)&quot;).get())<br>        yield scrapy.Request(<br>            url=book_url,<br>            callback=self.parse_book_detail,<br>            meta={&#39;category&#39;: category}<br>        )<br><br>    next_page = response.css(&quot;li.next a::attr(href)&quot;).get()<br>    if next_page:<br>        yield response.follow(next_page, callback=self.parse_category, meta={&#39;category&#39;: category})</pre><p>Reads the category name from <strong>meta.</strong></p><p>Extracts all books on the category page.</p><p><strong>For each book</strong>: Gets its detail page URL,Sends a request to scrape the book detail, passing along the category,</p><p><strong>Handles pagination</strong>: If a “next” page link exists, follows it recursively.</p><pre>def parse_book_detail(self, response):<br>    category = response.meta[&#39;category&#39;]<br><br>    def extract_table_data(label):<br>        return response.xpath(f&#39;//th[text()=&quot;{label}&quot;]/following-sibling::td/text()&#39;).get()<br><br>    yield {<br>        &quot;category&quot;: category,<br>        &quot;title&quot;: response.css(&quot;div.product_main h1::text&quot;).get(),<br>        &quot;upc&quot;: extract_table_data(&quot;UPC&quot;),<br>        &quot;product_type&quot;: extract_table_data(&quot;Product Type&quot;),<br>        &quot;price_excl_tax&quot;: extract_table_data(&quot;Price (excl. tax)&quot;),<br>        &quot;price_incl_tax&quot;: extract_table_data(&quot;Price (incl. tax)&quot;),<br>        &quot;tax&quot;: extract_table_data(&quot;Tax&quot;),<br>        &quot;availability&quot;: extract_table_data(&quot;Availability&quot;),<br>        &quot;number_available&quot;: int(&#39;&#39;.join(filter(str.isdigit, extract_table_data(&quot;Availability&quot;) or &quot;0&quot;))),<br>        &quot;review_rating&quot;: response.css(&quot;p.star-rating::attr(class)&quot;).re_first(r&quot;star-rating (\w+)&quot;),<br>        &quot;product_description&quot;: response.xpath(&#39;//div[@id=&quot;product_description&quot;]/following-sibling::p/text()&#39;).get(),<br>        &quot;book_url&quot;: response.url,<br>        &quot;number_of_reviews&quot;: int(extract_table_data(&quot;Number of reviews&quot;) or 0),<br>        &quot;image_url&quot;: response.urljoin(response.css(&quot;div.carousel img::attr(src)&quot;).get()),<br>    }</pre><ul><li>Gets the category name again from meta.</li><li>Defines a helper function extract_table_data(label):<br>* Finds the &lt;th&gt; element with matching label text.<br>* Returns the text from the adjacent &lt;td&gt; element.</li><li>Defines a helper function extract_table_data(label):<br>* Title, UPC, product type.<br>* Prices (excluding and including tax), tax amount.<br>* Availability (and parses number available as integer).<br>* Review rating (extracts the rating class name, e.g. “Three”).<br>* Product description (text after the description heading).<br>* Book page URL.<br>* Number of reviews (converted to int).<br>* Image URL (joined to full absolute URL).</li><li>yield returns the extracted data as a Python dictionary for Scrapy to process/export.</li></ul><h4>Step 3: Run Your Spider and Save Data</h4><p>To run the spider and save output to a JSON file, use this command in your project root:</p><pre>scrapy crawl books -o books_full.json</pre><p>This will start crawling and save the results in books_full.json in your current directory.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4395021b3da9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails Refactoring : Design Patterns in Ruby]]></title>
            <link>https://medium.com/@athiraramanan29/rails-refactoring-design-patterns-in-ruby-ab022f73f071?source=rss-55e510d6187b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab022f73f071</guid>
            <dc:creator><![CDATA[Athira Ramanan]]></dc:creator>
            <pubDate>Tue, 09 May 2023 07:43:53 GMT</pubDate>
            <atom:updated>2023-05-09T07:43:53.508Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rails Refactoring : Design Patterns in Ruby</h3><h3><strong>Part 1: Structural Design Patterns</strong></h3><p>Welcome to the first post in our series about Ruby on Rails Design Patterns. In each of the posts, we’ll take a deep dive into all sorts of patterns you might come across while working with Rails apps.In this post we are going to focus on <strong>Structural Patterns and Decorator Pattern...</strong></p><p><strong>What is a Design Pattern in programming?..</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*wH17zvnc6pLkb8HhX9Pchw.jpeg" /></figure><p>In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design.A design pattern will show you the way to the solution but it won’t give you a piece of code ready to be plugged into the rest of your software. It’s a guide for writing well-designed code in many different situations, but you have to come up with the implementation.</p><p><strong>What is a Structural Patterns?…</strong></p><p>Structural design pattern explains how to assemble the objects and classes in to larger structure.</p><ul><li>The structural design pattern shows how unique piece of a system can be combined together in an extensible and flexible manner.</li><li>We can target and change a specific parts of a larger structure without changing the entire structure.</li></ul><p><strong>When we want to focus on structural design pattern?…</strong></p><ul><li>As your project become complex and the number of classes and objectives will grow then go with structural pattern.</li><li>Structural pattern helps to simplifies the understanding of system and also easily identifies the relationship between classes.</li><li>It’s helps you to remove the redundancies and increase the level of abstraction and encapsulation among the classes.</li></ul><h4>What is the Decorator Pattern?</h4><p>The decorator pattern is structural design pattern that allows us to add behaviours to an instance without affecting the behaviours of all the instances of that class. We can “<strong><em>decorate</em></strong>” or add behaviours to a model instance before passing it to a view or even we can decorate an instance within a view.</p><p>Extracting complex presentation logic out of our views and models, and into decorator classes, we can simplify views(<em>only for presenting the data not responsible for its logic</em>) and models (<em>presentation logic isn’t models responsibility</em>), and decorate instances as needed.</p><p><strong>Hurrah</strong>! l<strong>et’s start with a real time example…</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ugleYWY5eU4-Znpadi_mcQ.png" /><figcaption><strong>Wearing clothes is an example of using decorators….</strong></figcaption></figure><blockquote><strong>W</strong>hen you’re cold, you wrap yourself in a sweater. If you’re still cold with a sweater, you can wear a jacket on top.If it’s raining, you can put on a raincoat.All of these garments “<strong>extend</strong>” our basic behaviour but aren’t part of you, and you can easily take off any piece of clothing whenever you don’t need it.</blockquote><p>Let’s get started !!!!</p><h4>Implementing the Decorator Pattern in View</h4><p>Let’s take an example of our view-related code smells 👎 the code we use to display a post’s published_at:</p><pre># app/views/posts/show.html.erb<br>&lt;%= @post.published_at.strftime(&quot;%A, %B %e&quot;) %&gt;</pre><p>The same code we need to use in some other places as well so we also need to repeat the same there. Not only is this code repetitious, here we are manipulating the date format as-well. This is not the responsibility of the view. The view just needs to sit there and look pretty 👰.</p><p>Let’s implement a decorator to handle the presentation of post’s published date.</p><ul><li>Create a subdirectory, app/decorators</li><li>Create a file app/decorators/posts_decorator.rb</li></ul><p>In decorator we are going to define a method named “<strong>display_date” </strong>this method handles the presentation logic.</p><pre># app/decorators/posts_decorator.rb<br><br>class PostsDecorator &lt; SimpleDelegator<br>  def display_date    <br>    object.published_at.gsub(&quot;-&quot;, &quot; &quot;).titleize<br>  end<br>end</pre><p>Now use it in the view !!!!</p><pre># app/views/posts/show.html.erb<br>&lt;%= PostsDecorator.new(@post).display_date %&gt;</pre><p>Next, we want to solve a model level code smell…</p><h4>Model Methods</h4><p>We have method in our Book model that deals the publishing company name of each book (deals with presentation logic)</p><pre># app/models/book.rb<br><br>def publishing_company_name<br>    company_id &amp;&amp; company.name.present? ? company.name : &quot;&lt;i&gt;Not yet published&lt;/i&gt;&quot;.html_safe<br>end<br><br></pre><p>Now use it in the view !!!!</p><pre>&lt;p&gt;Publisher: &lt;%= @book.publishing_company_name %&gt;&lt;/p&gt;</pre><p>As we said the model is not responsible for the presentation logic so it’s an example of violation of single responsibility principle.</p><p>Let’s define decorator for this !!!</p><pre># app/decorators/books_decorator.rb<br>class BooksDecorator &lt; SimpleDelegator<br>  def publishing_company_name<br>    object.company_id &amp;&amp; object.company.name.present? ? object.company.name :<br>                         &quot;&lt;i&gt;Not yet published&lt;/i&gt;&quot;.html_safe<br>  end <br>end</pre><p>Now use it in the view !!!!</p><pre>&lt;p&gt;Publisher: &lt;%= Book.new(@book).publishing_company_name %&gt;</pre><p>so in these 2 cases we completely takes the presentation logic to an another place to avoid the code smells….</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab022f73f071" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Difference between each, map, collect, select, inject, reduce, and detect in ruby]]></title>
            <link>https://medium.com/@athiraramanan29/difference-between-each-map-collect-select-inject-reduce-and-detect-in-ruby-6089f9202283?source=rss-55e510d6187b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6089f9202283</guid>
            <dc:creator><![CDATA[Athira Ramanan]]></dc:creator>
            <pubDate>Tue, 10 Aug 2021 23:35:32 GMT</pubDate>
            <atom:updated>2021-08-10T23:35:32.189Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*OqnxyEjECUP0AsKgQQUM7w.jpeg" /></figure><p>Everything in ruby is a object.Array is an object, In which each, map, select, collect, inject, detect are ruby methods for a object Array. Let’s understand all these methods thoroughly and the difference between these.</p><h3>1) Each</h3><p>Each is just a method on an object. That means that if you want to iterate over an array with each, you’re calling the each method on that array object.</p><p>It takes a list as it’s first argument and a block as the second argument. For every element in the list, it runs the block passing it the current element as a parameter.</p><p>You should use each when you want iteration but don’t care about what it returns.</p><p>let’s see an example.</p><pre>[1, 2, 3].each { |val| puts &quot;I am: #{val}&quot; }<br>I am: 1<br>I am: 2<br>I am: 3<br>=&gt; [1, 2, 3] </pre><p>It iterates over the array and return the original array not the calculated one.</p><pre>[1, 2, 4,5,6,3].each { |val| val&lt;4}<br>=&gt; [1, 2, 4, 5, 6, 3]</pre><h3>2) Map</h3><p>Map takes the enumerable object and a block, evaluates the block for each element and then return a new array with the calculated values.</p><pre>[1, 2, 4,5,6,3].map { |val| val*4}<br>=&gt; [4, 8, 16, 20, 24, 12]</pre><p>If you are try to use map to select any specific values like where val &lt;= 2 then it will evaluate each element and will output only the result which will be either true or false</p><pre>[1, 2, 4,5,6,3].map { |val| val&lt;=2}<br>=&gt; [true, true, false, false, false, false]</pre><h3>3) Collect</h3><p>Collect is similar to Map which takes the enumerable object and a block, evaluates the block for each element and then return a new array with the calculated values.</p><pre>[1,2,3,4,5,6,7,8,9,10].collect{ |val| val * 5 }<br>=&gt; [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]</pre><p>If you are try to use collect to select any specific values like where n &lt;= 5 then it will evaluate each element and will output only the result which will be either true or false</p><pre>[1,2,3,4,5,6,7,8,9,10].collect{ |val| val &lt;=5 }<br>=&gt; [true, true, true, true, true, false, false, false, false, false]</pre><h3>4) Select</h3><p>Select evaluates the block with each element for which the block returns true.</p><pre>[1,2,3,4,5,6,7,8,9,10].select{ |val| val &gt; 5 }<br># =&gt;  [6 ,7, 8, 9, 10]</pre><p>and also, select would return a element for which the statement is true.</p><pre>[1,2,3,4,5,6,7,8,9,10].select{ |val| val * 3 }<br># =&gt; [1,2,3,4,5,6,7,8,9,10]</pre><h3>5) Inject</h3><p>The inject method acts the same as the reduce method, and they are considered aliases. These enumerator methods can take a range or array of numbers, and can optionally receive a block. When called, the inject method will pass each element and accumulate each sequentially.</p><pre>[1,2,3,4,5,6,7,8,9,10].inject{ |sum, val| sum += val }<br># =&gt; 55</pre><pre>[1,2,3,4,5,6,7,8,9,10].inject(15){ |sum, e| sum += val }<br># =&gt; 70</pre><pre>[1,2,3,4,5,6,7,8,9,10].inject(1, :+)<br>=&gt; 56<br>This one is short hand. You could do the same syntax if you wanted to multiply each value, etc.</pre><pre>[{a: &#39;b&#39;},{c: &#39;d&#39;}].inject(:merge)<br>=&gt; {:a=&gt;&quot;b&quot;, :c=&gt;&quot;d&quot;}</pre><h3>6) Reduce</h3><p>Reduce is an enumerable method that can be used on hashes or arrays to reduce them into a single value or object.</p><pre>[1,2,3,4,5,6,7,8,9,10].reduce{ |sum, val| sum += val }<br>=&gt; 55</pre><pre> [1,2,3,4,5,6,7,8,9,10].reduce(15){ |sum, val| sum += val }<br>=&gt; 70</pre><pre>[1,2,3,4,5,6,7,8,9,10].reduce(1, :+)<br>=&gt; 56<br>This one is short hand. You could do the same syntax if you wanted to multiply each value, etc.</pre><pre>[{a: &#39;b&#39;},{c: &#39;d&#39;}].reduce(:merge)<br>=&gt; {:a=&gt;&quot;b&quot;, :c=&gt;&quot;d&quot;}</pre><h3>7) Detect</h3><p>The detect() of enumerable is an inbuilt method in Ruby returns the first element which satisfies the given condition in the block. If there is no block, then it returns the enumerator itself.</p><pre>array =(1..50).to_a<br>array.detect { |val|  val % 3 == 0 &amp;&amp; val % 9 == 0}<br>=&gt; 9</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6089f9202283" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>