teleren/devto huggingface dataset:
49 Days of Ruby: Day 21 - Inheritance
Tags: ruby
Published: 2021-04-17 16:44:13

---
title: 49 Days of Ruby: Day 21 - Inheritance
published: true
description: Join us on a 49 day learning journey through Ruby!
series: 49 Days of Ruby
tags: #ruby
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/9m73qaetuse3nm3y3it8.png
---

**Welcome to day 21 of the 49 Days of Ruby! 🎉**

Welcome back to 49 days of Ruby! Today, on day 21, we're going to discuss an important concept in understanding how Ruby works. An understanding of this topic will help you when you are writing your code. What is this concept? It's called *inheritance*. 

## What is inheritance?

Inheritance in programming is very similar to the widely used definition of the word in the broader world. It is essentially the idea that something descends from something else, and as a result **inherits** part of the ancestor's attributes.

Imagine, a child and parent relationship. The child descends from the parent, and children usually share some attributes of their parents. This is true generationally. Grandparents, great-grandparents, great-great-grandparents, and on.

As a result, inheritance in code is the idea that something comes from something else and shares aspects of what it comes from.

Let's take a look at it in Ruby.

## Inheritance in Ruby

What does inheritance in Ruby look like?

```ruby
class Parent
end

class Child < Parent
end
```

In the code example above we create a class called `Parent`. This is the **superclass*, or the parent class. After that, we create a class called `Child`, which is the **subclass**, or the child class. 

The `Child` class inherits from the `Parent` class with the special key of `<`. The direction of the carrot indicates the direction of the inheritance. In this case, the Parent is passing on its attributes to the Child.

As a result, let's say we had this kind of code:

```ruby
class Parent
  def self.say_hello
    puts "Hi!"
  end
end

class Child < Parent
end
```

The `Child` class would have access to the `#say_hello` method of the `Parent` class:

```ruby
> Child.say_hello

# => "hi!"
```

In Ruby every class has an inheritance tree. This inheritance tree is the family tree for the class. You can trace it all the way back to the original class. What's the original class for an object in Ruby? If you guessed `Object` you would be right!

Take a look at this example. In the example we ask what the `superclass` is for the `String` class:

```ruby
> String.superclass

# => Object
```

That's it for today! Come back tomorrow for day 22!

**Come back tomorrow for the next installment of 49 Days of Ruby! You can join the conversation on Twitter with the hashtag [#49daysofruby](https://twitter.com/hashtag/49daysofruby).**
Phase 1: Coding for the Future.
Tags: flatiron, reflection, projecttime
Published: 2021-04-17 17:31:38

With my first phase of Flatiron coming to a close, I've taken the time to do some self reflection over the last two months that I have been in the program.
On day one, I had absolutely no coding experience. My first few assignments were eye opening, pushing me out of my comfort zone and activating my technical mind like never before. 
In the beginning variables and iterations seemed complicated enough, but after spending hours upon hours doing assignments, research, and collaborating with others, Ruby is by no means mastered, but I consider myself very familiar and capable with the language.

At the end of the section, I had to create my own Command Line Interface (CLI). Now, I have built them before, but guided by tests and assignment requirements, so starting from scratch and creating my own was the true test.
I was quick to decide that my project will be a Final Fantasy character guide (FFX is my all time favorite game). Luckily, I was able to find a community created API => https://www.moogleapi.com/. 
From here using URI and JSON, I parsed through the URL and assigned it to my Character class.

     character_array = JSON.parse(response.body)
        character_array.each do |character|
            Character.new(character)

Now, in my character class I used key value pairs in a hash to grab the attributes that I wanted.
 
     :name, :job, :description

Then, in my CLI class, the fun began. Creating a menu that was interactive with the user looked like this:

     Welcome to the world of Final Fantasy!
 
     Are you ready to choose your Guardian?

Invalid message:

     You've shaken up the Chocobos!

Exit the program:

     May Yevon be with you.

I used the Moogle API to puts out ALL characters across every Final Fantasy game in an indexed list. By searching a name it output their attributes, for Tidus:

Name: Tidus.
 
Job: Guardian.
 
Description: Tidus (ティーダ Tīda) is the main protagonist of Final Fantasy X, a rising star blitzball player from Zanarkand. After the gargantuan monster known as Sin attacks his hometown, Tidus is transported to the world of Spira. Lost, confused, and seemingly out of place, Tidus meets a newly-fledged summoner named Yuna, and her guardians. Yuna is to set out on a pilgrimage to put an end to Sin, and by joining Yuna on her pilgrimage Tidus hopes he will find his way home. Yuna is the main protagonist in Final Fantasy X-2, but her relationship with Tidus works as the prime motivation for her to start her quest..

It took me just over a week to get my code running, the moment my program responded flawlessly was a moment of pure joy, relief, and pride. After two months of constant learning, coding, and assignment after assignment I have learned and retained more than I ever expected. 
After just one programming language, I am excited to delve deeper into the programming world. A hopeful jack of all trades, but still a master of none.
Protractor is officially being sunset
Tags: protractor, angular, e2e, testing
Published: 2021-04-17 17:14:40

Development will wrap up by the end of 2022, when they remove it from the Angular CLI and add warnings if it's force included in new Angular projects.

For more information, here's the whole thread on Github: [Future of Angular E2E & Plans for Protractor #5502](https://github.com/angular/protractor/issues/5502)

I already moved my projects to wdio, but I guess this means no more putting off writing my Protractor blog posts 😅
Getting back at blogging
Tags: devjournal
Published: 2021-04-17 17:14:11

Between the summer of 1665 and the spring of 1667, Isaac Newton made two long visits to Woolsthorpe in order to escape the plague affecting Cambridge. The bubonic ‘Great Plague’ of 1665–6 was the worst outbreak of plague in England. Issac did some amazing experiments with prism, hyperbola and gravity(famous apple incident)

## Where I have been …

Me who got endless time and freedom to pursue my personal endeavors, had my share of different explorations, with bullets:

🎓 Started the year as a college student and became alumini overnight.

🎉 Started my first full-time job

👷 Had a constant love-hate relationship with remote work.

🧑‍🍳 Learned some basic cooking

👨‍👦‍👦 Met a lot of people and friends online, for some of them it was literally impossible without the pandemic

💻 Got weirdly into raspberry pi's, homelabs, and servers.

🌳 Had some amazing life lessons overall

## Conclusion, Idk how to write blogs.xD

Using time efficiently doesn’t always mean being productive, having a fair share of explorations is important. Last year has been a whole new experience be it life, career or technical escapades.

2020 if nothing gave me a good port to host my internal services on 😆

I am trying to get back to blogging again. I think bringing structure to the week is important, will try to have a weekly and biweekly schedule from now.

Thanks for sticking around 🙂.
Things I learned this week.
Tags: softskills, tips
Published: 2021-04-17 17:04:34

Before we go into the topic I want to first introduce myself as this is my first blog post on here. I am an aspiring web developer, who aims to be a junior developer by the end of the year. I started my coding journey in Autumn last year when I joined a brilliant non-profit organisation called CodeYourFuture, and today I will publish some thoughts and tips I learnt during the week, which I believe can give a little of help to people who are on the same journey as me.

- **Why Soft skills are important?**

Just remember this “Hard skills will get you the interview, but Soft skills will get you the job”,  this is one of the things I have learned from the people in the industry and thanks for coming to my Ted talk. 

But no seriously, Soft skills are skills that relates to your personal skills such as communications skills, teamwork, leadership, open-mindedness and the list goes on.

Enhancing your Soft skills should take the same effort as your Hard skills (technical skills), because when recruiters wanna hire you as a junior, it is not because of your tech skills (as you do not have the experience yet), it is because they want to hire someone who thinks and behaves like a programmer and this is where you can use your Soft skills to demonstrator this, and I heard this directly myself from the senior developers/managers who work in well known companies.

You might be also surprised that leaderships is among those skills that are deemed important for a junior to possess. Well first let me tell you that you do not need to lead a group of developers and mentor them to be regarded as a leader. 

Leadership is about learning from your mistakes and taking the necessary steps to overcome challenges, anything that challenges your inner self for the better good is a sign of leadership, deciding to advocate some time to enhance your skills is a sign of leadership, being honest and confident is a sign of leadership.

There are a lot of skills that are categorised under Soft skills signs, quick online search about them will tell you what they are and how to improve them. This [link](https://pointjupiter.com/soft-skills-software-developer-need-ultimate-guide/) is a page that explores Soft skills more in depth. 

- **A tip I got on how to get my first dev role.**

I got the following advice from a person who works in the recruitment agency,
and what she suggested is to connect with and speak to the right people on LinkedIn.

The best way to utilize this is to speak with people from the internal team, such as “Talent manager", "Head of people", "internal recruiter" "Recruitment manager" "Resourcing advisor".

The method to use is to message/email them directly and make a tailored message for each message/email you send, as it will show them how much interest and effort you are putting in to get a job with them.

Please feel free to share your suggestions or feedback if you wish.
Kotlin Sort Object List with Kotlin Selector function – crossinline selector: (T) -> R?

Tags: kotlin, selector, crossinline
Published: 2021-04-17 16:58:03

https://grokonez.com/kotlin/kotlin-sort-object-list-kotlin-selector-function-crossinline-selector-t-r

Kotlin Sort Object List with Kotlin Selector function – crossinline selector: (T) -> R?

In the tutorial, <a href="https://grokonez.com">JavaSampleApproach</a> will show you how to <strong>Sort Kotlin Object List</strong> with <strong>Kotlin Selector</strong> function - <code>crossinline selector: (T) -> R?</code>

Related posts:
- <a href="https://grokonez.com/kotlin/kotlin-sort-list-objects-kotlin-comparator-example">Sort List of Objects with Kotlin Comparator Example</a>
- <a href="https://grokonez.com/kotlin/kotlin-sort-list-objects-comparable">Sort List of Objects with Kotlin Comparable</a>
- <a href="https://grokonez.com/kotlin/kotlin-binary-search-object-list-comparison-function-comparison-t-int">Kotlin Binary Search for Object List with Comparison function – comparison: (T) -> Int</a>
- <a href="https://grokonez.com/kotlin/kotlin-binary-search-object-list-selector-function-crossinline-selector-t-k">Kotlin Binary Search for Object List with Selector function – crossinline selector: (T) -> K?</a>

<!--more-->
<h2>I. Technologies</h2>
– Java 1.8
– Kotlin 1.1.61

https://grokonez.com/kotlin/kotlin-sort-object-list-kotlin-selector-function-crossinline-selector-t-r

Kotlin Sort Object List with Kotlin Selector function – crossinline selector: (T) -> R?
Kotlin Sort Object List with Kotlin Selector function – crossinline selector: (T) -> R?

Tags: kotlin, selector, crossinline
Published: 2021-04-17 16:55:50

https://grokonez.com/kotlin/kotlin-sort-object-list-kotlin-selector-function-crossinline-selector-t-r

Kotlin Sort Object List with Kotlin Selector function – crossinline selector: (T) -> R?

In the tutorial, <a href="https://grokonez.com">JavaSampleApproach</a> will show you how to <strong>Sort Kotlin Object List</strong> with <strong>Kotlin Selector</strong> function - <code>crossinline selector: (T) -> R?</code>

Related posts:
- <a href="https://grokonez.com/kotlin/kotlin-sort-list-objects-kotlin-comparator-example">Sort List of Objects with Kotlin Comparator Example</a>
- <a href="https://grokonez.com/kotlin/kotlin-sort-list-objects-comparable">Sort List of Objects with Kotlin Comparable</a>
- <a href="https://grokonez.com/kotlin/kotlin-binary-search-object-list-comparison-function-comparison-t-int">Kotlin Binary Search for Object List with Comparison function – comparison: (T) -> Int</a>
- <a href="https://grokonez.com/kotlin/kotlin-binary-search-object-list-selector-function-crossinline-selector-t-k">Kotlin Binary Search for Object List with Selector function – crossinline selector: (T) -> K?</a>

<!--more-->
<h2>I. Technologies</h2>
– Java 1.8
– Kotlin 1.1.61
<h3>II. Kotlin Sort Object List with Selector</h3>
We have <code>sortedBy(crossinline selector: (T) -> R?)</code> for ascending sorted list, and <code>sortedByDescending(crossinline selector: (T) -> R?)</code> for descending sorted list.

- Method signature of <code>sortedBy(crossinline selector: (T) -> R?)</code>

<pre><code class="language-java">
public inline fun <T, R : Comparable<R>> Iterable<T>.sortedBy(crossinline selector: (T) -> R?): List<T>
</code></pre>

- Method signature of <code>sortedByDescending(crossinline selector: (T) -> R?)</code>

<pre><code class="language-java">
public inline fun <T, R : Comparable<R>> Iterable<T>.sortedByDescending(crossinline selector: (T) -> R?): List<T>
</code></pre>

So We need define an appropriate <strong>selector</strong> function for them.

-> <strong>Step to do</strong>:
<ul>
<li>Create data model</li>
<li>Create selector function</li>
<li>Do Sorting</li>
</ul>

More at:

https://grokonez.com/kotlin/kotlin-sort-object-list-kotlin-selector-function-crossinline-selector-t-r

Kotlin Sort Object List with Kotlin Selector function – crossinline selector: (T) -> R?
Kotlin Map methods – maxBy() maxWith()
Tags: kotlin, maxby, maxwith, map
Published: 2021-04-17 16:52:22

https://grokonez.com/kotlin/kotlin-map-methods-maxby-maxwith

Kotlin Map methods – maxBy() maxWith()

In the tutorial, <a href="https://grokonez.com">JavaSampleApproach</a> will show how to use Kotlin Map methods <code>maxBy()</code>, <code>maxWith()</code>.

<!--more-->
<h2>I. Kotlin Map methods - maxBy() maxWith()</h2>
<h3>1. maxBy()</h3>
<code>maxBy()</code> returns the first entry having largest value of the given function <code>selector: (Map.Entry<K, V>) -> R</code> or 'null' if there are no elements.
Method signature:

<pre><code class="language-java">
public inline fun <K, V, R : Comparable<R>> Map<out K, V>.maxBy(selector: (Map.Entry<K, V>) -> R): Map.Entry<K, V>?
</code></pre>

Practice:

<pre><code class="language-java">
val productMap = hashMapOf("iPhone 8 Plus 64G" to  Product("iPhone 8 Plus 64G", "Apple", 850.00),
							"Samsung Galaxy S8 64GB Unlocked Phone" to Product("Samsung Galaxy S8 64GB Unlocked Phone", "Samsung", 699.99),
							"iPad Pro 9.7-inch 32 GB" to Product("iPad Pro 9.7-inch 32 GB", "Apple", 474.98),
							"Samsung Electronics Ultra HD Smart LED TV" to Product("Samsung Electronics Ultra HD Smart LED TV", "Samsung", 677.92),
							"Google Pixel Phone - 5 inch display" to Product("Google Pixel Phone - 5 inch display", "Google", 279.95),
							"iPad Pro 9.7-inch 128G" to Product("iPad Pro 9.7-inch 128G", "Apple", 574.99),
							"Google Wifi system 1-Pack" to Product("Google Wifi system 1-Pack", "Google", 149.90),
							"Samsung Galaxy Tab 4" to Product("Samsung Galaxy Tab 4", "Samsung", 127.67))

// public inline fun <K, V, R : Comparable<R>> Map<out K, V>.maxBy(selector: (Map.Entry<K, V>) -> R): Map.Entry<K, V>?
var productsWithMaxPrice = productMap.maxBy { (_, product) -> product.price }
println("Key: ${productsWithMaxPrice?.key}, Value: ${productsWithMaxPrice?.value}")
// print on console
// ->
/*
	Key: iPhone 8 Plus 64G, Value: Product(name=iPhone 8 Plus 64G, madeBy=Apple, price=850.0)
*/
</code></pre>
<h3>2. maxWith()</h3>
<code>maxWith()</code> returns the first entry having the largest value according to the provided [<strong>comparator</strong>]
Method signature:

More at:

https://grokonez.com/kotlin/kotlin-map-methods-maxby-maxwith

Kotlin Map methods – maxBy() maxWith()
A simple and easy way to validate form fields
Tags: webdev, javascript, beginners
Published: 2021-04-17 16:50:18

Hello guys, in this post I will talk about the simplest and easiest way to validate form fields according to my point of view, please enjoy.

* First, let's create the validators.js file:

```javascript
    
export const myValidators = {


        isEmpty (string) {
                if(string.trim() === '') {
                    return true;
                } else {
                    return false
                }
        }, 


        isEmail(email)  {
            const emailRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

            if(email.match(emailRegExp)) {
                return true;
            } else {
                return false;
            }
        },



    isLength(string, value) {
        if(string.length < value) {
            return true
        } else {
            return false
        }
    },



    
}

```


*  And finally, we will create the inputFields.js file:
```javascript

import { myValidators } from './validators.js'


// TODO: testing isEmail() method
const isEmailMethod = () =>
{
    let errors = {};
    const email = "jaimeinoque20@gmail.com";
    if (!myValidators.isEmail(email))
    {
      errors.email = "Email Field must be valid!"  
    } else
    {
        console.log(email)
    }
     
    if(Object.keys(errors).length > 0 ) {
        return console.log(errors)
    }
}

isEmailMethod()


// TODO: testing isLength method
const isLengthMethod = () =>
{
    let errors = {};
    const password = "849350920@sofala";
    if (myValidators.isLength(password, 9))
    {
      errors.password = "your password is too short"  
    } else
    {
        console.log(password)
    }
     
    if(Object.keys(errors).length > 0 ) {
        return console.log(errors)
    }
}

isLengthMethod()


// TODO: testing isEmpty method
const isEmptyMethod = () =>
{
    let errors = {};
    const phone = "849350920";
    if (myValidators.isEmpty(phone))
    {
      errors.phone = "Phone Field must not be empty!"  
    } else
    {
        console.log(phone)
    }
     
    if(Object.keys(errors).length > 0 ) {
        return console.log(errors)
    }
}

isEmptyMethod()
```

## Thank you all
Why my posts are the way they are .
Published: 2021-04-17 16:39:16

## Background Information about me :

So if y’all were wondering , I am a grade 12 student who’s interested in programming . I find ML and Cybersecurity interesting and am hoping to get into these fields after college . I love talking about things I find interesting and I also like the concept of open source . 

## About my posts : 
As a student who’s new to programming , I know for a fact that I am not qualified to teach others as I do not have enough knowledge to teach . So this brings me to the topic of my posts . As mentioned above , I love talking about things I find interesting , if you have seen any of my other posts , I’ve spoken about Pi network , general advice , ubuntu and a bit about open source . Though this may not help anyone in particular , I find it interesting so I want to share it to people . I’ve had over 800 views on my posts till date and I have 3 reactions per post . I know it may be that reactions isn’t proportional to the amount of people who find it interesting but as a student I’ve always had the thing that the more the reactions , the more people who liked it . 

So what I want to say is that , if you’re new here and you don’t get enough reactions , don’t let that get to you , if you like something , share it , talk about the things you like . You do You .

If you’ve reached out so far , thank you . Hope you’re doing good and I hope this post makes sense , do not know whether or not to make this a temporary post but if you’re new person , keep sharing things you find interesting don’t hold back . As long as you’re happy that’s all that matters . Cheers
Convert Kotlin Map to List
Tags: kotlin, map, list
Published: 2021-04-17 16:38:11

https://grokonez.com/kotlin/kotlin-tutorial-convert-kotlin-map-list

Convert Kotlin Map to List

In the tutorial, <a href="https://grokonez.com">Grokonez</a> will show you how to convert <strong>Kotlin Map to List</strong>.

Related posts:
- <a href="https://grokonez.com/kotlin/convert-kotlin-list-map">Convert Kotlin List to Map</a>

<!--more-->
<h2>I. Convert Kotlin Map to List</h2>
<h3>1. Basic Method</h3>
- Use <code>public fun <K, V> Map<out K, V>.toList(): List<Pair<K, V>></code> to returns a <code>[List]</code> containing all key-value pairs

<pre><code class="language-java">
val simpleMap = hashMapOf("foo" to 1, "bar" to 2)
val pairKeyValueList = simpleMap.toList()
println(pairKeyValueList) // [(bar, 2), (foo, 1)]
</code></pre>

- Use <code>public Collection<V> values()</code> to return a view of the values:

<pre><code class="language-java">
val valueList = simpleMap.values
println(valueList) // [2, 1]
</code></pre>

- Use <code>public Set<K> keySet()</code> to return a set view of the keys:

<pre><code class="language-java">
val keyList = simpleMap.keys
println(keyList) // [bar, foo]
</code></pre>
<h3>2. Map Object</h3>
- When working with Map Object, we can associate with <code>map(transform: (T) -> R)</code> function to customize a returned-list:

More at:

https://grokonez.com/kotlin/kotlin-tutorial-convert-kotlin-map-list

Convert Kotlin Map to List