<?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>Forem: Felix Imbanga</title>
    <description>The latest articles on Forem by Felix Imbanga (@feelo31).</description>
    <link>https://forem.com/feelo31</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%2F1257573%2Febb5096e-72a5-448d-ac63-e3f6fa3ad937.jpeg</url>
      <title>Forem: Felix Imbanga</title>
      <link>https://forem.com/feelo31</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/feelo31"/>
    <language>en</language>
    <item>
      <title>More Classes</title>
      <dc:creator>Felix Imbanga</dc:creator>
      <pubDate>Sat, 23 Mar 2024 04:08:44 +0000</pubDate>
      <link>https://forem.com/feelo31/more-classes-3292</link>
      <guid>https://forem.com/feelo31/more-classes-3292</guid>
      <description>&lt;p&gt;def year=(new_year): Defines a setter method that allows you to set the value of @year with car.year = 2022.&lt;br&gt;
def year(new_year): Defines a regular instance method that needs to be called with car.year(2022) and does not assign the value to @year unless you explicitly do so inside the method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sentences = [
  "the dog, the cat, the zebra, the giraffe",
  "the, the code, and the developer",
  "then the- their"
]
sentence = sentences.sample
pp sentence
# write your program below
the_count = sentence.scan(/\bthe\b/).count
pp "'the' appeared #{the_count} times"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The issue with the code is how the .count method is being used. The .count method in Ruby, when used on strings, doesn’t count occurrences of whole words but instead counts individual characters that match any in the set of characters provided as an argument. In this case, new_sentence.count("the") is counting each occurrence of ‘t’, ‘h’, and ‘e’ individually, not the word ‘the’.&lt;/p&gt;

&lt;p&gt;To count occurrences of the whole word ‘the’, you would need to use a different approach, such as using the .scan method with a regular expression that matches the word ‘the’ followed by a boundary to ensure it’s a whole word:&lt;/p&gt;

&lt;p&gt;Here, /\bthe\b/ is a regular expression where \b denotes a word boundary, ensuring that only the whole word ‘the’ is matched, not ‘the’ within other words like ‘then’ or ‘their’. The .scan method returns an array of all matches, and calling .count on that array gives you the number of times the whole word ‘the’ appeared in the sentence.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>If statements</title>
      <dc:creator>Felix Imbanga</dc:creator>
      <pubDate>Wed, 20 Mar 2024 16:49:28 +0000</pubDate>
      <link>https://forem.com/feelo31/if-statements-ah0</link>
      <guid>https://forem.com/feelo31/if-statements-ah0</guid>
      <description>&lt;p&gt;Type &lt;code&gt;end&lt;/code&gt; immediately after typing the &lt;code&gt;if&lt;/code&gt;. Indent &lt;br&gt;
&lt;code&gt;elsif&lt;/code&gt; is only when you need to check more than 2 conditions. &lt;br&gt;
Causing code to execute is known as 'truthy'&lt;br&gt;
Causing code to not execute is known as 'falsy'&lt;br&gt;
Only &lt;code&gt;nil&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt; are falsy. &lt;br&gt;
&lt;code&gt;!=&lt;/code&gt; means not equivalent&lt;br&gt;
&lt;code&gt;p&lt;/code&gt; if for quick inspection, &lt;code&gt;pp&lt;/code&gt; is for more human readable representations. especially with complex data structures. &lt;br&gt;
In variables you can put methods on both sides to evaluate &lt;code&gt;if&lt;/code&gt; statements more concise. &lt;br&gt;
&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; both statements have to be true&lt;br&gt;
&lt;code&gt;||&lt;/code&gt; at least one statement has to be true. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Integer, Float, and Array class</title>
      <dc:creator>Felix Imbanga</dc:creator>
      <pubDate>Wed, 20 Mar 2024 16:42:19 +0000</pubDate>
      <link>https://forem.com/feelo31/integer-float-and-array-class-24jg</link>
      <guid>https://forem.com/feelo31/integer-float-and-array-class-24jg</guid>
      <description>&lt;p&gt;&lt;strong&gt;Integer class&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;/&lt;/code&gt; when dividing only returns the whole&lt;br&gt;
&lt;code&gt;%&lt;/code&gt; returns the remainder&lt;br&gt;
Rubyists tend to end method names with a question marks when methods return &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
&lt;code&gt;rand&lt;/code&gt; returns a random number. &lt;code&gt;rand(n)&lt;/code&gt; will return a random integer between 0 and n-1 rather than 1 and n &lt;br&gt;
&lt;code&gt;object#method&lt;/code&gt; is different from &lt;code&gt;object.method&lt;/code&gt;&lt;br&gt;
&lt;code&gt;.to_f&lt;/code&gt; is useful in converting an integer to a float.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Float class&lt;/strong&gt;&lt;br&gt;
Division with floats works the way we're used to. It returns fractional results, as a &lt;code&gt;float&lt;/code&gt;. &lt;br&gt;
If either number when dividing with &lt;code&gt;\&lt;/code&gt; is a float, float division will be performed. &lt;br&gt;
&lt;code&gt;rand&lt;/code&gt; can also be called without methods.&lt;br&gt;
&lt;code&gt;push == &amp;lt;&amp;lt;&lt;/code&gt; for shorthand. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Array class&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;.at&lt;/code&gt; method in an array refers to the index, which starts at 0. &lt;code&gt;nil&lt;/code&gt; represents absence of in index in the array aka doesn't exist. &lt;br&gt;
In an array, to count backwards through a list of items, start with -1 (aka the last item)&lt;br&gt;
&lt;code&gt;.at == object[index]&lt;/code&gt; shorthand.&lt;br&gt;
&lt;code&gt;.index&lt;/code&gt; method returns the index where it resides&lt;br&gt;
&lt;code&gt;.split&lt;/code&gt; will return an array of substrings&lt;br&gt;
&lt;code&gt;.split&lt;/code&gt; with an argument tells the program to split at the character of the argument.&lt;br&gt;
&lt;code&gt;.split&lt;/code&gt;ing with an empty argument &lt;code&gt;("")&lt;/code&gt; turns a string into an array of individual characters. &lt;br&gt;
&lt;code&gt;.count&lt;/code&gt; counts how many items are in a list if called with no arguments. If an argument is provided it counts how many times that argument occurs in the list.&lt;br&gt;
&lt;code&gt;.sample&lt;/code&gt; returns an unpredicted item from an array&lt;/p&gt;

</description>
      <category>development</category>
    </item>
    <item>
      <title>String and Date classes</title>
      <dc:creator>Felix Imbanga</dc:creator>
      <pubDate>Wed, 20 Mar 2024 16:27:54 +0000</pubDate>
      <link>https://forem.com/feelo31/string-and-date-classes-17fc</link>
      <guid>https://forem.com/feelo31/string-and-date-classes-17fc</guid>
      <description>&lt;p&gt;&lt;strong&gt;String Class&lt;/strong&gt;&lt;br&gt;
Formal way to create a new object is with the &lt;code&gt;.new&lt;/code&gt; method&lt;br&gt;
&lt;code&gt;.concat&lt;/code&gt; method accepts a number as a method, interprets it as an ASCII code, translates it from a single character, and adds it to the end of an original story.&lt;br&gt;
&lt;code&gt;.concat&lt;/code&gt; can be replaced with &lt;code&gt;+&lt;/code&gt;, you can also drop the &lt;code&gt;.&lt;/code&gt;, as well as the parenthesis.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Class&lt;/strong&gt;&lt;br&gt;
Arguments within &lt;code&gt;pp&lt;/code&gt; &lt;code&gt;p&lt;/code&gt; &lt;code&gt;print&lt;/code&gt; or &lt;code&gt;puts&lt;/code&gt; need to be seperated with a comma or with interpolation. &lt;code&gt;Date.parse()&lt;/code&gt; accepts a string and converts it to a &lt;code&gt;Date&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;String Interpolation + printing&lt;/strong&gt;&lt;br&gt;
Alternative to &lt;code&gt;.to_s&lt;/code&gt;&lt;br&gt;
Easier when it comes to composing strings&lt;br&gt;
Only double quotes interpolate&lt;br&gt;
&lt;code&gt;pp&lt;/code&gt; shows the gory technical details, which is usually what you want when debugging code. It calls &lt;code&gt;inspect&lt;/code&gt; on whatever object you give it. backend?&lt;br&gt;
&lt;code&gt;puts&lt;/code&gt; calls a method &lt;code&gt;.to_s&lt;/code&gt; on whichever object you give it. Better for human interaction, frontend?&lt;br&gt;
&lt;code&gt;\n&lt;/code&gt; represents a new paragraph or line break. An active character.&lt;br&gt;
&lt;code&gt;\s&lt;/code&gt; represents a space between within a line. &lt;br&gt;
Single quotes within double quotes is one way to include a string within a string. &lt;br&gt;
If you want double quotes you need to use the escape character backslash.&lt;br&gt;&lt;br&gt;
&lt;code&gt;"\"Felix\""&lt;/code&gt; ---&amp;gt; &lt;code&gt;"Felix"&lt;/code&gt;&lt;br&gt;
The &lt;code&gt;\&lt;/code&gt; before &lt;code&gt;"&lt;/code&gt; says treat this next quotation as a character not as the string literal syntactic sugar.&lt;br&gt;
&lt;code&gt;ms&lt;/code&gt; = multiline string as long there is one opening and closing quote. &lt;/p&gt;

</description>
      <category>webdev</category>
    </item>
    <item>
      <title>What, why, how</title>
      <dc:creator>Felix Imbanga</dc:creator>
      <pubDate>Wed, 20 Mar 2024 16:13:19 +0000</pubDate>
      <link>https://forem.com/feelo31/what-why-how-1mj6</link>
      <guid>https://forem.com/feelo31/what-why-how-1mj6</guid>
      <description>&lt;p&gt;Ruby has a lot of advantages for beginners. Rails is also good for small teams, and solo developing. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;self&lt;/code&gt; is a special object that represents different objects at different times.&lt;br&gt;
&lt;code&gt;pp&lt;/code&gt; is a method we use to call the main object "pretty print"&lt;br&gt;
syntactic sugar makes things easier to print&lt;br&gt;
&lt;code&gt;object.method&lt;/code&gt; - the primary method to write examples. what we will be using most often&lt;br&gt;
&lt;code&gt;object.method(parameter)&lt;/code&gt; - make up an expression which is the return value. &lt;br&gt;
&lt;code&gt;self.pp&lt;/code&gt; is more useful when debugging or when you want to inspect data in a more human reading format. Shows the structure and nesting which makes it easier to understand complex nested objects.&lt;br&gt;
&lt;code&gt;gsub&lt;/code&gt; - globally substitute, will replace all occurrences of one substring w another substring. Often used to remove illegal characters from usernames before saving. &lt;br&gt;
Skill leves as a programmer is essential and about the number of error messages that you have encountered in the past and now recognize. &lt;br&gt;
use &lt;code&gt;#comments&lt;/code&gt; liberally. &lt;br&gt;
&lt;code&gt;=&lt;/code&gt; - variable assignment operator, evaluates right side first. Most ruby methods don't modify the object they are called upon. Rather they just return a modified copy. &lt;br&gt;
Variables can only contain lowercase letters, numbers, and underscores, no spaces and cant begin with a number. They should be descriptive no matter the length.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Object oriented programming</title>
      <dc:creator>Felix Imbanga</dc:creator>
      <pubDate>Tue, 19 Mar 2024 00:59:10 +0000</pubDate>
      <link>https://forem.com/feelo31/object-oriented-programming-4gif</link>
      <guid>https://forem.com/feelo31/object-oriented-programming-4gif</guid>
      <description>&lt;p&gt;Almost everything in ruby is an object. Class names in ruby use CamelCase. &lt;code&gt;initialize&lt;/code&gt; is a method used to boot up each object the class creates. Use &lt;code&gt;@&lt;/code&gt; before a variable to signify that it always is an instance variable. This means that the variable is attached to the instance of the class. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;@&lt;/code&gt; - whenever a class is created, it has to have your &lt;code&gt;@&lt;/code&gt; and each instance of your class will have its own &lt;code&gt;@&lt;/code&gt;. Scope of a variable is the context in which it is visible to the program. &lt;/p&gt;

&lt;p&gt;Global variable - available everywhere&lt;br&gt;
Local variable - only available in methods&lt;br&gt;
Class - only available in classes&lt;br&gt;
Instance - only available in instances of classes.&lt;/p&gt;

&lt;p&gt;Class variable begin with &lt;code&gt;@@&lt;/code&gt;&lt;br&gt;
Global variables inside a method or class begin with &lt;code&gt;$&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Inheritance - process by which one class takes on the attributes and methods of another. It is used to express and is-a relationship. When you call &lt;code&gt;super&lt;/code&gt; from inside a method, that tells ruby to look in the superclass of the current class and find a method with the same name as the one from which &lt;code&gt;super&lt;/code&gt; is called. If it finds it, ruby will us the superclass version of the method. Mixins, allow for data and functions of multiple classes to be put in one. &lt;/p&gt;

&lt;p&gt;If you want to end a ruby statement without going on a new line you can just type a semicolon. &lt;/p&gt;

&lt;p&gt;Public methods allow for an interface with the rest of the program. Private methods are for classes to do their work undisturbed. In private methods, methods cannon be called with an explicit receiver. in order to access private info we have to create public methods such as &lt;code&gt;attr_reader&lt;/code&gt; and &lt;code&gt;attr_writer&lt;/code&gt;. These are shorthand notations for defining getter and setter methods within a class for instance variables. Important in object orienting encapsulation principle. &lt;/p&gt;

&lt;p&gt;module - a toolbox that contains a set of methods and constants. These are written in CamelCase. Constants included in methods are defined with all caps. &lt;/p&gt;

&lt;p&gt;name-spacing - how ruby separated methods and constants.&lt;br&gt;
scope resolution operation - ruby's way of saying it tells rubys where you're looking for a specific bit of code. &lt;/p&gt;

&lt;p&gt;If we say &lt;code&gt;Math::PI&lt;/code&gt; ruby knows to look inside the math module to get that PI, not any other PI. &lt;/p&gt;

&lt;p&gt;In the following code : &lt;code&gt;def initialize (name, balance=100)&lt;/code&gt;&lt;br&gt;
This signifies an optional parameter&lt;br&gt;
Ruby is saying that you can pass 1 or 2 arguments to &lt;code&gt;initialize&lt;/code&gt;. If you pass 2, it uses your balance argument to set &lt;code&gt;@balance&lt;/code&gt;. If you only pass &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;balance&lt;/code&gt; gets a default value of 100 and this is what is stored in &lt;code&gt;balance&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;In Ruby , private methods can be called without an explicit receiver within the context of a class. &lt;/p&gt;

</description>
      <category>learning</category>
    </item>
    <item>
      <title>Blocks, Procs, and Lambdas</title>
      <dc:creator>Felix Imbanga</dc:creator>
      <pubDate>Tue, 19 Mar 2024 00:37:45 +0000</pubDate>
      <link>https://forem.com/feelo31/blocks-procs-and-lambdas-55g3</link>
      <guid>https://forem.com/feelo31/blocks-procs-and-lambdas-55g3</guid>
      <description>&lt;p&gt;Lambdas - nameless methods. This is how methods accept blocks using the yield keyword.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.collect&lt;/code&gt; method - returns a copy of a variable, doesn't change or mutate the original variable. ie &lt;code&gt;.collect!&lt;/code&gt; in which the &lt;code&gt;!&lt;/code&gt; means this method can do something dangerous in ruby.&lt;/p&gt;

&lt;p&gt;Blocks - these are one of the few exceptions of things that aren't objects in ruby. Bit of code between &lt;code&gt;do&lt;/code&gt; or &lt;code&gt;end&lt;/code&gt; or &lt;code&gt;{}&lt;/code&gt;, but can be passed to methods like &lt;code&gt;.each&lt;/code&gt; or &lt;code&gt;.select&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Proc - a block which is saved to a variable. Good for keeping code DRY aka Dont Repeat Yourself. &lt;/p&gt;

&lt;p&gt;To pass a proc to a method expecting a block use &lt;code&gt;&amp;amp;&lt;/code&gt; right before the the parameter. &lt;/p&gt;

&lt;p&gt;Procs are objects so they have the power/abilities of objects and can be called over and over. This prevents you from having to retype the contents of your block every-time you need to execute a particular block of code. &lt;/p&gt;

&lt;p&gt;We can call procs directly by using ruby's &lt;code&gt;.call&lt;/code&gt; method&lt;/p&gt;

&lt;p&gt;Remember, in ruby there is always more than one way to do something. &lt;/p&gt;

&lt;p&gt;I learned I cant &lt;code&gt;puts&lt;/code&gt; a proc because it is an object not a string, this will print the memory address instead of a proc. procs are callable objects that contain blocks of code and to see the effect of the code within a proc, you must call it. Lambdas are also objects. &lt;/p&gt;

&lt;p&gt;**Lambdas vs procs&lt;br&gt;
Lambdas check the number of arguments passed to it while a proc does not. This means lambdas will give an error if you a pass it the wrong number of arguments. While a proc will ignore unexpected arguments and assign &lt;code&gt;nil&lt;/code&gt; to any missing arguments. &lt;br&gt;
When Lambdas &lt;code&gt;return&lt;/code&gt;, control is passed back to the calling method. When a proc &lt;code&gt;return&lt;/code&gt;s it does so immediately without going back to the calling method. &lt;br&gt;
&lt;code&gt;&amp;amp;&lt;/code&gt; is used to pass a lambda.&lt;br&gt;
&lt;code&gt;()&lt;/code&gt; and &lt;code&gt;{}&lt;/code&gt; are important in the syntax of lambdas. &lt;/p&gt;

</description>
      <category>webdev</category>
    </item>
    <item>
      <title>String Interpolation/Refactoring in Ruby</title>
      <dc:creator>Felix Imbanga</dc:creator>
      <pubDate>Thu, 14 Mar 2024 21:37:00 +0000</pubDate>
      <link>https://forem.com/feelo31/string-interpolationrefactoring-in-ruby-8k0</link>
      <guid>https://forem.com/feelo31/string-interpolationrefactoring-in-ruby-8k0</guid>
      <description>&lt;p&gt;You can always add &lt;code&gt;+&lt;/code&gt; or &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; to add a variable value into a string &lt;code&gt;"#{interpolation}"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Refactoring - fancy way of saying we're improving the structure or appearance of code without changing what it actually does.&lt;br&gt;
   Omit needless words&lt;br&gt;
   Make sure to us the when defining methods&lt;br&gt;
   Using &lt;code&gt;puts&lt;/code&gt; inside methods is generally discouraged if the  methods are meant to be used as part of a library or for refactoring values as it can lead to unwanted console output. &lt;code&gt;puts&lt;/code&gt; is mostly used for debugging or for scraping that interaction directly with the user via the terminal.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Zen of Ruby</title>
      <dc:creator>Felix Imbanga</dc:creator>
      <pubDate>Thu, 14 Mar 2024 17:20:14 +0000</pubDate>
      <link>https://forem.com/feelo31/zen-of-ruby-4b7</link>
      <guid>https://forem.com/feelo31/zen-of-ruby-4b7</guid>
      <description>&lt;p&gt;Ternary operation- takes 3 arguments; boolean, expression to determine if boolean is true + one to determine falseness&lt;br&gt;
syntax = &lt;code&gt;boolean? Do this if true(Evaluate this if true):Do this if false(Evaluate this if false)&lt;/code&gt;&lt;br&gt;
   Only requires 1 &lt;code&gt;puts&lt;/code&gt; statement at boolean part.&lt;br&gt;
&lt;code&gt;||&lt;/code&gt; - used to only assign a variable which hasn't been assigned. &lt;code&gt;nil&lt;/code&gt; is ruby for nothing. &lt;br&gt;
Ruby's method will return the result of the last evaluated expression unlike python where you have to explicitly state the evaluation. No need for return&lt;/p&gt;

&lt;p&gt;Short circuit evaluation&lt;br&gt;
Better tools to handle repetitive tasks in ruby than &lt;code&gt;for&lt;/code&gt; loops. To evaluate a specific number of times use &lt;code&gt;.times&lt;/code&gt; method. To repeat an action for every element in a collection use &lt;code&gt;.each&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;Single blocks are great for short/concise operations where multi line blocks using &lt;code&gt;do&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; are more practical for longer/more complex operations. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Refactoring - Ruby</title>
      <dc:creator>Felix Imbanga</dc:creator>
      <pubDate>Tue, 12 Mar 2024 17:03:51 +0000</pubDate>
      <link>https://forem.com/feelo31/refactoring-ruby-3l0k</link>
      <guid>https://forem.com/feelo31/refactoring-ruby-3l0k</guid>
      <description>&lt;p&gt;&lt;code&gt;case&lt;/code&gt; statement - a concise alternative to &lt;code&gt;if/else&lt;/code&gt; statements. I wondered why there's so much change between the syntax of  &lt;code&gt;case&lt;/code&gt; and &lt;code&gt;if/else&lt;/code&gt; statements. &lt;/p&gt;

&lt;p&gt;There should be 4 verbs of your programs operations aka operations that add, display, update, and delete or CRUD for short. These are actions you take when you update an entry in a database, ask a website for info, write a blog post. I'll see these in everything from API calls to web frameworks like ruby on rails. &lt;/p&gt;

&lt;p&gt;Ruby is a language prioritizing program productivity over program optimization. &lt;/p&gt;

&lt;p&gt;I don't need and &lt;code&gt;end&lt;/code&gt; when my &lt;code&gt;if&lt;/code&gt; statement is on one line. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Ordering your library + Hashes and symbols</title>
      <dc:creator>Felix Imbanga</dc:creator>
      <pubDate>Sat, 02 Mar 2024 21:33:25 +0000</pubDate>
      <link>https://forem.com/feelo31/ordering-your-library-hashes-and-symbols-4e84</link>
      <guid>https://forem.com/feelo31/ordering-your-library-hashes-and-symbols-4e84</guid>
      <description>&lt;p&gt;Today I worked on ordering my library as well as hashes and symbols. I learned about &lt;code&gt;def&lt;/code&gt; methods and parameters. Also learned about &lt;code&gt;rev=false&lt;/code&gt; and this causes &lt;code&gt;def&lt;/code&gt; methods to default to false if the user types in 2 arguments. I should also remember to put &lt;code&gt;==&lt;/code&gt; in conditionals, I've been making the mistake of putting &lt;code&gt;=&lt;/code&gt; which is used for assignment. &lt;/p&gt;

&lt;p&gt;Building on methods is great for using code over and over without having to retype things but it is also great for abstracting or simplifying your program. &lt;/p&gt;

&lt;p&gt;There are two ways to write hashes&lt;br&gt;
Hash literal notation is &lt;code&gt;new_hash = { "one" =&amp;gt; 1 }&lt;br&gt;
or&lt;/code&gt;new_hash = Hash.new`&lt;/p&gt;

&lt;p&gt;Along with false, nil is one of 2 non-true values in ruby. Every other object is regarded as truthful. False means not true. nil is ruby's way of saying nothing at all. &lt;/p&gt;

&lt;p&gt;You can add key/value pairs in &lt;code&gt;Hash.new&lt;/code&gt; like this:&lt;br&gt;
&lt;code&gt;empty_hash = Hash.new&lt;/code&gt;&lt;br&gt;
&lt;code&gt;empty_hash.store(:key, "value")&lt;br&gt;
If you want to provide a default value for any key that doesnt exist in the hash, pass this argument &lt;/code&gt;default_hash = Hash.new("default")&lt;code&gt;. This will return &lt;/code&gt;default&lt;code&gt; instead of &lt;/code&gt;nil`. The hash is empty until you explicitly add key-values when using this method.&lt;/p&gt;

&lt;p&gt;symbols- can only be one copy of a particular symbol at a given time. They can start with a &lt;code&gt;:&lt;/code&gt; and spaced with a &lt;code&gt;_&lt;/code&gt;. They are primarily used with hash keys for referencing method names. They are immutable meaning they cant be changed once created. Only one copy exists at a given time, saving memory. Symbol-as-keys are faster than string-as-keys. &lt;code&gt;.to_s&lt;/code&gt; is to string while &lt;code&gt;.to_sym&lt;/code&gt; converts to symbol. &lt;code&gt;.intern&lt;/code&gt; is also another way to convert to a symbol. &lt;/p&gt;

&lt;p&gt;With the new update, symbol syntax has changed to where you put the &lt;code&gt;:&lt;/code&gt; after the symbol instead of before it, you dont need the hash rocket anymore. &lt;/p&gt;

</description>
      <category>webdev</category>
    </item>
    <item>
      <title>Blocks and Sorting Ruby</title>
      <dc:creator>Felix Imbanga</dc:creator>
      <pubDate>Fri, 01 Mar 2024 03:37:00 +0000</pubDate>
      <link>https://forem.com/feelo31/blocks-and-sorting-ruby-385h</link>
      <guid>https://forem.com/feelo31/blocks-and-sorting-ruby-385h</guid>
      <description>&lt;p&gt;This is a good example of methods and splat arguments from codeacademy's training&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def what_up(greeting, *friends)
  friends.each { |friend| puts "#{greeting}, #{friend}!" }
end

what_up("What up", "Ian", "Zoe", "Zenas", "Eleanor")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Methods are reusable sections of code that perform a specific task in a program&lt;/p&gt;

&lt;p&gt;seperation of concerns- make program less redundant and code more readable.&lt;/p&gt;

&lt;p&gt;Methods defines a new&lt;br&gt;
-header include the &lt;code&gt;def&lt;/code&gt; key word&lt;br&gt;
-Body included the procedure the methods carries out&lt;br&gt;
-end includes the &lt;code&gt;end&lt;/code&gt; key word&lt;br&gt;
argument - code that you put between a methods parenthesis when you call it, parameter is the name you put between methods parenthesis when you define it. &lt;/p&gt;

&lt;p&gt;Splat argument - argument preceding an asterisk.  tells program you can use 1 or more arguments&lt;/p&gt;

&lt;p&gt;&lt;code&gt;puts&lt;/code&gt; always returns nil when included in a method. you must use something like &lt;code&gt;return&lt;/code&gt; because puts will be evaluated in the expression&lt;/p&gt;

&lt;p&gt;ruby evaluates for expression truthiness/falsiness. An expression in ruby will inherently return a boolean value when used in a context that expects a boolean. Without needing explicit statements of &lt;code&gt;return false&lt;/code&gt; or &lt;code&gt;return true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;abstraction - making something simpler. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;sort&lt;/code&gt; is non destructive while &lt;code&gt;sort!&lt;/code&gt; is destructive. the first stores original string while the latter erases and completely creates a new string. they each have their benefits based on what you plan on doing with your code. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;=&amp;gt;&lt;/code&gt; means if 1&amp;gt;2 then 1 is returned, if 1&amp;lt;2, -1 is returned, and if the values are equal 0 is returned. Also be careful not to set this equal to a variable because ruby will print out the numeric value to the console, rather than ordered strings. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
