<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kasia Ekiert</title>
    <description>The latest articles on DEV Community by Kasia Ekiert (@multikasia).</description>
    <link>https://dev.to/multikasia</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1184090%2F3d2c06d0-1baf-4455-bd72-00d018912ddd.png</url>
      <title>DEV Community: Kasia Ekiert</title>
      <link>https://dev.to/multikasia</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/multikasia"/>
    <language>en</language>
    <item>
      <title>Bang! methods</title>
      <dc:creator>Kasia Ekiert</dc:creator>
      <pubDate>Sat, 28 Oct 2023 14:56:23 +0000</pubDate>
      <link>https://dev.to/multikasia/bang-methods-1h6</link>
      <guid>https://dev.to/multikasia/bang-methods-1h6</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ToKe9Sux--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m1jzteztjxfzx4nhfyxb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ToKe9Sux--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m1jzteztjxfzx4nhfyxb.png" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ruby Bang methods (!) are a naming convention that indicates that a method can be "dangerous" or modify its receiver. For example, &lt;code&gt;downcase!&lt;/code&gt; changes the original string to lowercase, while &lt;code&gt;downcase&lt;/code&gt; returns a new string. Bang methods are not always destructive, but they usually want to get your attention.&lt;br&gt;
The merge! method is a way to combine two hashes into one, by adding the contents of the second hash to the first one. If the hashes have duplicate keys, the values from the second hash will overwrite the values from the first one.&lt;/p&gt;

&lt;p&gt;Ruby on Rails Bang methods (!) are methods that raise an exception when something goes wrong, such as finding a record in the database or saving a model.&lt;/p&gt;

&lt;p&gt;Metody Bang w Ruby i w Ruby on Rails to metody, które używamy z wykrzyknikiem.&lt;br&gt;
Co osiągamy poprzez użycie ! ?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Zapisujemy zamiane na obiekcie.&lt;/li&gt;
&lt;li&gt;Użycie metody merge! na hashach powoduje powstanie nowego hasha - z dwóch podanych. Jeśli w drugim hashu będą zduplikowane klucze - z pierwszego hasha - zostaną nadpisane (chyba, że zostanie to wcześniej rozwiązane inaczej ;)&lt;/li&gt;
&lt;li&gt;W Ruby on Rails użycie ! dodatkowo - sprawdza walidacjami czy dany obiekt może powstać i zwraca nam ewentualne errory.&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Usage of method reduce in Ruby</title>
      <dc:creator>Kasia Ekiert</dc:creator>
      <pubDate>Wed, 25 Oct 2023 08:35:43 +0000</pubDate>
      <link>https://dev.to/multikasia/usage-of-method-reduce-in-ruby-2329</link>
      <guid>https://dev.to/multikasia/usage-of-method-reduce-in-ruby-2329</guid>
      <description>&lt;p&gt;Usage of reduce in ruby and a task: &lt;br&gt;
Write a program that displays the sum of predecessors for the next 10 natural numbers. Expected result: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55.&lt;/p&gt;

&lt;p&gt;My solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def counter(n)
  sum = 0 
  letters = []
  (1..n).each do |number|
    sum += number
    letters &amp;lt;&amp;lt; sum
  end
  letters.join(", "). #remember to create an array first and then to join letters inside
end 

puts counter(10) #result: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require './training1'

RSpec.describe '#counter' do
  subject { counter(n) }

  context 'It gives partial sums of the numbers' do
    let(:n) { 10 }

    it "should return a line of numbers" do
      expect(subject).to eq("1, 3, 6, 10, 15, 21, 28, 36, 45, 55")
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But if we don’t need to display all numbers and we need just a sum of them, we may use the method reduce:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
def counter(n)
  (1..n).reduce(:+) 
end 

puts counter(10) #result: 55
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://apidock.com/ruby/Enumerable/reduce"&gt;https://apidock.com/ruby/Enumerable/reduce&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enjoy :)&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
