Customizing the items from a select field using Set operators

I had to customize the items of a select input field for timezones in a form. I needed to show some preferred US timezones first and then list the remaining below them. My mentor sent me this link to help me and I want to share it with you.

It turns out, this is something that you probably saw in a Math class: Set theory. What we need here is what we call Union:

A union is essentially used to combine the unique values of two sets, or in this case, arrays. To perform a union on two arrays you use the pipe as an operator. For example:

[1, 2, 1, 2, 3] | [1, 2, 3, 4] #=> [1, 2, 3, 4]

Mike Farmer

Or visually:

image from mathscrunch

Now that we are a little more familiar with set operators, let’s move to our problem. To keep our code organized, let’s move our code to a helper:

 # we use helpers to extract logic from our views
  
def timezones
  priorities =
    [ ActiveSupport::TimeZone['Eastern Time (US & Canada)'],
     ActiveSupport::TimeZone['Central Time (US & Canada)'],
     ActiveSupport::TimeZone['Mountain Time (US & Canada)'],
     ActiveSupport::TimeZone['Pacific Time (US & Canada)'] ]
    
  priorities | ActiveSupport::TimeZone.us_zones
end

So first we have a list of the preferred timezones, then we use the | operator to show those first and after that, show all the US time zones that aren’t included on the priorities list.

Now we just need to call our helper method on our form:

# html.slim

= f.collection_select :time_zone, timezones, :name, :to_s, {}, { class: "form-control" }

And voilà, that’s the result:

ta-da!

Whenever you have a similar problem, you can follow this approach. Hope you liked it!

Some awesome Bootstrap 4 Responsive Utilities

Bootstrap has made our lives easier because of its responsive utilities (recommended having a basic HTML and CSS knowledge before playing with Bootstrap).  I’ve been using Bootstrap 4 for the past 7 months and I was surprised at the really good features and amazing utilities they released on this version. I want to share some valuable lessons from studying those docs. And please, if you have others as well, please share! 🙂

Bootstrap Grid

To give a brief context, keep in mind that Boostrap uses a property called Grid System. For this tutorial, all you need to understand is how those grids are broken into five  breakpoints, one for each screen size, from extra small to extra large devices:

// Extra Small devices (Portrait phones)
// .col-xs-*
@media (min-width: 576px) { }

// Small devices (Landscape phones)
// .col-sm-*
@media (min-width: 576px) { }

// Medium devices (tablets, 768px and up)
// .col-md-*
@media (min-width: 768px) { }

// Large devices (desktops, 992px and up)
// .col-lg-*
@media (min-width: 992px) { }

// Extra large devices (large desktops, 1200px and up)
// .col-xl-*
@media (min-width: 1200px) { }

That means you can modify them as you need and being aware of those breakpoints is pretty useful, including when you want to show or hide some content dependig on the screen size.

Usage

Now let’s go to the fun part, the examples:

  • To maintan a consistent responsiveness to you app, use col-* , so you don’t need to rely on any breakpoint to organize the elements on your page (keep in mind that depending on what you want, you may need to set a breakpoint):
// Regardless of the screen size, the columns will always have the same width

<div class="row">
  <div class="col-3">
    <div class="card">
      <div class="card-body">
        < ... >
      </div>
    </div>
  </div>
  <div class="col-9">
    < ... >
  </div>
</div>
  • Hide content depending on the screen size:
// this card will be visible only on lg screen

<div class="card d-none d-lg-block">
  <div class="card-body">
    < ... >
  </div>
</div>
  • If we want to the opposite, i.e., show on every grid except on the lg sizes, we can use the .d-lg-none class to the element:
// this list of icons be hidden on screen >= lg

<div class="fixed-bottom">
  <div class="card d-lg-none">
    <div class="nav-icons card-body">
      < ... >
    </div>
  </div>
</div>

Example

Here I have a screencast showing all of that together, resulting in a very fully responsive page, without any weird behaviour when switching between the screen size:

Hope you liked this. I was really impressed of how Boostrap 4 has made our lives easier. Enjoy it!

Creating your own Ruby new method

I’ve been studying more of Ruby from RubyTapas and I even got back to an old project of mine, the RubyFarm. I’m here today to show one really cool thing that I learned today: how to personalize the new method.

In order to do that, Ruby needs from us three things (from RubyTapas):

1 – Allocate a new, empty object of the given class.
2 – Run any specialized initialization code defined for the class
3 – Return the initialized instance

So if we would rewrite the RubyFarm Animal new instance method, for example, we could do something like:

class Animal
  def self.create_new(*args, &block)
    instance = allocate
    instance.my_initialize(*args, &block)
    instance
  end

  def my_initialize(breed, age, weight, last_vaccine)
    @breed = breed
    @age = age
    @weight = weight
    @last_vaccine = last_vaccine
  end
end

bob = Animal.create_new('domestic cat', 5, 8, 2017)
p bob # => <Animal:0x00005644aaa17800 @breed="domestic cat", @age=5, @weight=8, @last_vaccine=2017>

And voilà! Ruby really makes it easier to creates your own methods. Thanks, Avdi for all of those lessons 🙂

Hope you found that as awesome as I did when I learned this. See you next time!

Why I love the web

I am a junior back-end developer who recently discovered the exciting world of UX. If you take a look at my posts, you can see how passionate I am about working with Technology. I’m also aware that our industry lacks discussing relevant topics such as mental health, diversity (beyond race and gender) and accessibility and how important initiatives that aim to change are necessary.

When I was studying Computer Science in Brazil (only did one year and a half), I worked on an undergraduate research using Python and Arduino to create a game prototype for children with visual impairment issues. The idea is to have some physical pieces that would allow them to learn the basic of Math equations by playing with them. The computer gives instant feedback for them and it was an amazing journey to work on this. I have an article (this was the very first MVP, later) and the code is on my Github.

I also made the course Design and Make from Girls in Tech. I prototyped a dice that suggests some boost-mood activities for people who struggle with anxiety and depression, helping them to motivate to do their daily activities. I wrote about this process here, in case you want to check it out.

And I would say what I love more about the web is how we can create things from nowhere, just using our creativity to solve real-world problems. And how using Technology can bring those solutions to a large number of people.

A funny thing about my tech journey so far is that up until now, I always thought that being a back-end developer and a UX enthusiast were exclusive interests but… I couldn’t be more wrong! In fact, thinking on the whole process turns my life as a developer even better because now I try to think on the whole process and how to make the user more comfortable with what I am building.

With all that in mind, currently my goals for the next year are:

  • FInish my studies on Structure and Interpretation of Programs;
  • Practice more my UI/UX skills;
  • Write more and Speak at tech events. I like to share what I’m learning because it’s really hard to put all the pieces together when you are a beginner and people often assume you should already know stuff.
  • JavaScript. I have more experience with the back-end so far. I must say that Javascript is something that I don’t feel too comfortable with but I would like to learn more.

 

And that’s all, folks! While I was reading this, I realized how my interests have changed… and that is awesome! Until next time!

Design and Make Course – Girls in Tech

I did the Girls in Tech Design and Make Course (by Autodesk) a few weeks ago and I’m here to share my experience (and hopefully inspire you to take this course too!). I didn’t know before, but Girls in Tech have a platform called Global Classroom where you can sign up for different courses. Don’t forget to check it out!

About the course

The modules, the links, the extra materials… everything about this course was really well put together. We learned all the process involved in using Technology as a tool to solve problems, rather than an end itself. I must say that I became fascinated with Product Design and 3D Modeling after taking this course.

The main topics that we discussed were Product Design, Prototyping, and Iteration. We had to gather data and inspiration on a challenging issue, think of a Design Concept and iterate on different versions of the prototype after getting feedback and experimenting.

To achieve all of that, we used Tinkercad to model our prototype. Erica Nwankwo, our facilitator, shared some cool tutorials – especially from Instructables, for us to practice along the course. She also posted many motivational videos and posts 🙂

My first 3D product – Boost my Mood

I made some research on CBT – Cognitive-behavioural Therapy. I wanted to create something that would help people facing a cycle of negative thoughts or lacking motivation. This is something that I personally am familiar with and I wanted to explore this theme.

I first thought about creating a board game where you could identify your cognitive distortion and prevent you to get into the cycle of negative thoughts and a dice to suggest mood-lifting activities. But I realized that I would need more time to practice my 3D skills to model both, so I eventually stuck with the dice.

This is something that I’ve been learning after reading Feeling Good, by Dr. David Burns: action must anticipate motivation. It helps when I feel like not able to do nothing or just wanna stay in bed, so I can roll the Boost my Mood and do one of the activities to cheer me up!

You can see by the next images that I’m not much skilled at drawing, but hey, we all need to start at some point, right?

my raw sketches!

Here is the prototype of my Boost my Mood dice:

prototyping is fun!

Here you can check the first version of my 3D model.

Autocad Contest

As our final assignment, we had to submit a presentation, a kind of a summary of our previous 5 weeks of work.

Autodesk made a contest to select the 10 best presentations and offered to print the 3D models. The presentation included:

  1. Problem Statement & Design Brief
  2. Design Concept & Sketches
  3. Prototypes & 3D Model
  4. Storyboard

 

I made my presentation using Google Drive and you can take a look at it by clicking here. After all of that, I can’t express how happy I was when Erica sent me an email announcing that my presentation was one of the 10 selected! <3

(I didn’t model all the icons, there is this repository where you download  3D models for free called Thingiverse. It helped a lot. That was a great resource because otherwise, I would take more time to model all of those icons :P).

It was an amazing experience, I’m really grateful for this opportunity. The idea of thinking about a problem, creating a product and having it in your hand, is something that I could never think of before. I encourage you to try this process by yourself and let me know if you want to share it with me. Cheers!

 

Rails Girls Summer of Code logo

Rails Girls Summer of Code 2018

Rails Girls Summer of Code is a great way to practice your code skills after attending to one of the Rails Girls workshops. You can work on an Open Source project during the Summer, having a whole team to support you: teammate, a mentor, coaches and a supervisor to support you during this journey. I still get excited when I remember that this program is totally funded by the community (and also some cool sponsors!).

I am so happy to say that my team, Brazilian Housewives coding, was accepted this year! They recently posted my team Introduction blog post from the official blog in Rails Girls Summer of Code. Check it out the other team’s posts there too, they are all amazing!

About us

Hello! We are Stefanni and Camila, two junior software developers from Brazil, based in Vancouver, Canada. We didn’t know each other before the RGSoC and we are more than happy to introduce our team!

Stefanni

I am a millennial that likes to cook, coding, cats, playing sports and eating chocolate. I moved to Vancouver in January because my husband received a job offer to work here and we brought our two cats with us.

My history with Rails Girls began in 2015. Actually, Rails Girls is the reason I decided to start Computer Science college in 2015 ( I only did 1 year and a half, now I am studying by myself). I went as a student in the Rails Girls Sao Paulo 2015 workshop and since then I wanted to join the RGSoC, but I never applied. I was also a coach on the 2017th edition and it was an amazing experience.

The other coach of my group introduced me to the CTO of a Brazilian fintech where later I did a brief software internship before moving to Vancouver. So imagine how happy I was when Ana and Vaishali surprised us announcing that we were selected, Rails Girls has been playing an important role in my tech career!

Camila

Hello everybody, my name is Camila! I’m a Brazilian living in Vancouver with my husband. After finishing our master’s degree in Computer Science last year we came to Canada with our two cats – the flight was a great adventure!

During graduation I worked with Recommender Systems, characterizing the consumption over time in recommendation domains, and in social network analysis. In my master, I was interested in understanding how sociological aspects are reflected in current technologies, such as the existence of racial bias/stereotypes in search engines, and what is the role of the algorithms on the propagation of these bias/stereotypes. I’ve been working with academic research since my first year as an undergrad student. And my plan was to finish my master’s degree and then apply for a Ph.D. But for now, I feel the need to apply my knowledge to something that is really going to be used by several people and not only in the academic environment.

I learned to code in my early years of graduation and I have a good experience with algorithms. I have good knowledge of Python, C, R… But I have almost no experience in software development, software engineering, testing, etc. So I think the Rail Girls program will be a great opportunity to be part of the Open Source community and learn a lot!

How did we meet?

Because we are both relatively new to Vancouver, it was difficult to find a teammate here. So we used the RGSoC google groups to search for teammates and there was where we met each other. We went to a coffee shop and discussed our application and we soon got along, especially because we both have cats =).

Thanks, RGSoC organizers for providing these mediums for us to find a teammate 🙂

How is work going?

This week has been great! We are reading and collecting information from the Public Lab codebase and the API docs/tests. Also, we focused on learning more about Git, RESTful API’s, and how to document code changes.

We also want to thank the Predictable Revenue for letting us use their space to work. Thiago, one of our coaches, works there and we asked if we could work there. The office is great and it’s located at the historical site of Vancouver, a central location in the city.

Camila, Julio, Stefanni and Thiago on our first day! picture taken by Stefanni Brasil

Camila, Julio, Stefanni, and Thiago on our first day! the picture was taken by Stefanni Brasil

Meet our Amazing Team

Coaches:

Thiago Araujo and Julio Albinati. Thanks for being our coaches, we couldn’t be part of this amazing program without your help.

Mentor:

One of the reasons we applied to work at Public Lab is because it’s a very inclusive and supportive community. Jeff Warren is always helping us and we are happy to be part of it.

Supervisor:

Mayar is our RGSoC’s Buddy and we want to thank you for all your support and advice for us to have a great summer of code.

Thanks, everyone for helping us and for being part of our team, you are amazing! 🙂

About our Summer Project

We are working as a part-time team on the Public Lab app, more specific on the API feature. We have a Planning Issue here with the Timeline and a Github Project page if you want to check out and/or give some help and tips 🙂 We don’t have much experience working with API’s so we are really excited to learn everything that we can this summer.

So, why Brazilian housewives coding?

We are junior developers and have only been living in Vancouver for a few months. We were both beginning our career in Brazil when our husbands got a job offer to move to Vancouver so we were having a hard time finding opportunities for juniors here. We thought it would be a good name to play with our status here! 😛

What do we expect for the RGSoC 2018?

  • Understand more about modeling an API
  • Become more familiar with SQL queries
  • Be experts on Ruby on Rails
  • Learn more about JavaScript and Tests
  • Improve our documentation skills
  • Be just the beginning of this amazing Open Source adventure
  • Have a great Summer!

Peak: Secrets from the New Science of Expertise

I discovered a few months ago this cute app called Libby that allows you to loan e-books and audiobooks using your local library card without having to log in, download the e-book, send to your device… Isn’t that amazing?! <3

When I was reading Deep Work, I added a few books in my to-read Bookshelf and one of them was Peak: Secrets from the New Science of Expertise, from by K. Anders Ericsson and Robert Pool. It is, so far, one of the best books involving psychological research and concepts that I have read (the other one is ‘Thinking, Fast and Slow’, by Daniel Kahneman).

It’s not my intention here to resume the book or to discuss every concept of it (there are so many!!). But to give you an idea, the book discusses how to be an expert in a given field through a deliberate practice, building mental representations, having the support of your significant ones and other variables.

Now I want to share with you my best part of the book. It’s the chapter 8, ‘But What About Natural Talent?’, specifically, the section called ‘The Dark Side of Believing In Inner talent’. It demystifies the belief of someone being gifted or being talented by nature and because of that, they are good at what they do.

When people assume that talent plays a major, even determining, role in how accomplished a person can become, that assumptions points one toward certains decisions and actions. If you assume that people who are not innately gifted are never going to be good at something, then the children who don’t excel at something right away are encouraged to try something else. The clumsy ones are pushed away from sports, the ones who can’t carry a tune right away are told they should try something other than music, and the ones who don’t immediately get comfortable with numbers are told they are not good at math. And, no surprises, the predictions come true [… ]. Te prophecy becomes self-fufilling.

Because we believe in that, we don’t even try. And that can prevent people from building great skills that would benefit us all as a society. That is so damaging! I was one of these children who was discouraged to study Engineering… That’s too bad that it happened, but now I understand that this is a huge social problem and I wasn’t the only one. And I am changing that now. If you identify yourself with that, I hope you are doing that too 🙂

In addition to this discussion, I think that this belief is more prejudicial in the STEM fields. I have heard so many times people saying: ‘there are some people who learn how to code really fast, they must be naturally good at it’ or ‘I don’t have a logical brain, therefore I can’t learn how to code’. Now I try to show them the learning from this book and hope that they will stop repeating that and will at least try to pursue their goals.

There is one more quote that I want to share to finish this post with a positive quote:

In the long run it is the ones who practice more who prevail, not the ones who had some initial advantage in intelligence or some other talent.

If you liked these quotes, then besides reading the entire book, you will also enjoy this free amazing and fantastic resources by Dr. Stephen Chew to apply to your practices. You are very welcome!

Hope that you get interested in reading it and if you do, share here your thoughts of it. Or recommend me another book. Cheers!

Github guide for Open Source Contributions

I’ve always wanted to contribute to Open Source projects and I am proud to say that recently I achieved that by doing my first code contributions to some cool projects! There are lots of resources online about contributing to Open Source Projects, especially from Github, but it doesn’t hurt writing another one, right? And writing this Guide will help me because now I don’t have to search the commands every time 🙂

For me, the hardest part was finding a project where I felt welcomed as a beginner and comfortable with the technology used. I was looking at the Rails Girls Summer of Code projects and after some days, I started doing contributions to Public Lab and If me organizations.

If I am in any position of giving an advice, I’d say to look out for projects that you feel comfortable and that makes sense to you and to your learning path. It probably isn’t a good idea to start contributing to the Linux kernel, if you are learning how to program, for example.

You can take a look at the open Issues and choose one that you want to work. If you think you can work on an Issue, for example, but need to clarify some things, go ahead and ask the team! 🙂

Another thing that is helpful in this discovery adventure is to read the documentation. Providing a careful documentation usually says a lot about the team communication and organization.

I like to follow these two guides from Lucas Mazza and Thoughtbot to help me with Git in my contributions. I recommend you to read these two before going further.

Setting our application

Now that we have selected the project and selected an Issue to work on, we must go to their repository and click on the ‘Fork’ button:

This will create a new repository in our Github Account with the current state of the application. You can see it by clicking on your account’s repositories. That’s the repository where we’ll add our changes, instead of playing with the original. This is good because it guarantees that we’ll never affect the original repository, so we won’t be afraid of breaking something and focus on our work 🙂

Now, on our local machine, we clone our forked project (remember to modify the personal info with yours):

git clone git@github.com:stefannibrasil/plots2.git

The next step is to make sure everything is running okay, following the project Installation guide. After that, we can go ahead and create a new branch in our forked repository:

git checkout -b 'my-new-branch'

It’s up to you if you want to create a new branch or work on your local master. I prefer always having a branch for each new feature.

Now we have everything ready for our actual work! Remember to write good commit messages and provide good context for the reviewers while doing them. This post helped me a lot with that 🙂

Submitting our changes

When we are done with our changes, the next step is to open a Pull Request to say that we want to merge our changes into the original code. Normally, visiting the Github project page after pushing changes from a local branch will put a notice with the branch name.

I find it easier to open the Pull Request just clicking on ‘Compare & Pull Request’:

But if that doesn’t happen, you can do that by clicking on ‘New pull request’ and search for your branch there.

Note: If you aren’t done yet but you want to know if you are on the right path, you can always open a new PR to get some feedback. Just add a ‘[WIP] – Add new feature’ to its name and ask for a review.

Keeping our forked repository updated

Because other people are making modifications to the code at the same time, our forked repository needs to get these changes frequently, so we will always have the updated code to work on.

We can do that by adding the project repository as one of our remote repositories. We can copy the link provided in the original repository ‘clone or download’ button and run the following command:

git remote add upstream git@github.com:publiclab/plots2.git

Now if we run

git remote -v

we should have two remote repositories listed, ours and the project’s:

origin git@github.com:stefannibrasil/plots2.git (fetch)
origin git@github.com:stefannibrasil/plots2.git (push)
upstream https://github.com/publiclab/plots2.git (fetch)
upstream https://github.com/publiclab/plots2.git (push)

Now run these on master:

git fetch upstream # to retrieve new work done by ther people
git rebase upstream/master # to rebase upstream into your master
git push origin master

If that ran smoothly, you must see that your forked repository is even with the original:

If you’ve created a branch as I did, run the following command to also rebase your branch with the updated master:

git checkout my-new-branch
git rebase master/my-new-branch

Now we have our repository updated and that will decrease the number of conflicts in the future. If conflicts happen, it’s not the end of the world. Git usually provides helpful messages about the errors to guide you while solving them (and Google, always).

Some notes

After doing your first Open source contribution you’ll likely find out that the code that you change is just half of the work. You need first to communicate with the team, see if you understand the problem and ask for help, for example.

But don’t worry if you don’t feel ready to do any of this. Don’t let that hold you back. If the project you choose is beginner-friendly, the team will help you with anything that you need. Besides, you’ll learn a lot from this experience, trust me.

Another note that I want to share is this video from Eileen. She talked a little about her Open Source experience developing a feature for Rails 5.1:

And that’s it for today. I hope you find this Guide useful. If you have anything to suggest or add, please, add a comment below 🙂 See you next!

 

Some random thoughts

Hello, there!

It’s been a while since I don’t write anything here. For those who don’t know, my husband and I moved this year to Vancouver, Canada and that took us some time to solve everything but now I am back! 🙂

This got me thinking about how hard it is for us, humans, to change. This isn’t my first moving, in fact, this is the 4th time I am moving to another city in the past 10 years. You have to start everything again: meet new people -hopefully, make a new friend- learn the culture, habits, etc.

But you don’t need to move to another country to change any aspect of your life. No matter what it is, you have to show up and say to the world what you want. The best opportunities that happened to me was because I pushed myself to go there, even when I was in doubt. I am not saying every opportunity will be great, but at least you’ll learn something from the experience.

Don’t think I didn’t feel scared. I was, but I am feeling better about my choices since I started trying to think about what could go right, always. You should try it.

Object-Oriented Programming with Ruby pt. 1

I had OOP in my college last year and it was a bummer. Looking back, I may have learned the most valuable skill for developers: being a developer == a full-time self-learner (a new concept that I just invented).

But since I quit college and started my internship last year, I felt the need to go back to the basics and finally be able to write good code using OOP fundamentals. I started a Rails tutorial and I noticed that I have never run a Ruby program (without rails) on my terminal!

What I learned most from this experience was that I should focus on learning the foundations before the frameworks, for example: learn Ruby before Ruby on Rails. I wanted to understand why Ruby became so popular and what makes OOP a paradigm so important in Computer Science.

I found a lot of resources online and one of them is the MIT Computer Science which offers a complete Introduction to Computer Science and Programming with Python and I decided to make some notes about it but in Ruby. OOP is given in lectures 14, 15 and 16 if you want to give it a try too. Also found the Docs — Programming Ruby which is a complete material to follow. Both these materials helped me study and are guiding this post 🙂

This is the part one, which will be an introduction to OOP introductory concepts, like Class and Objects. I also started a repository on GitHub where I apply what I am studying to keep a record.

Abstract everything

OOP is not a new concept in Computer Science, but it became very popular only on the 70’s. But why do we need OOP and why did it become so popular? Quoting Prof. Eric Grimson:

Object Oriented Programming is great when you are trying to model systems that consist of a large number of units that interact in various ways.

That’s why OOP is so vastly used and solves a huge amount of problems in our real life because we can solve almost every problem with this paradigm! By gathering together some data it allows you to write better code, which means it is easier to test and to refactor.

we are all objects

Let’s go back to the basics

Everyone who starts to study OOP start to hear a lot about ClassesObjects, and Instances. Let’s explore them a little theoretically.

Classes, Objects, Instances

You must have heard that in Ruby, everything is an object: a Class is an Object; An Instance is an Object and an Object is… I think you get the idea! Although in our real world we deal with lots of objects, it’s hard to abstract it to code — at least for me. But once we understand the purpose of it and the concepts behind it, it starts to make more sense and things start to get easier #hopefully.

A Class is a collection of data and functions that make sense to stay together because they have characteristics in common. It helps your daily work by preventing you from spreading pieces of code through different files.

As prof. Eric Grimson said in one of his classes, it’s easier if think of a Class like a stamp: you can print several objects of a Class using its stamp. Every new object created using a stamp will have the same characteristics but they will still be different objects because they are unique copies of that stamp, they’re randomly allocated in different locations in memory.

And why are objects so useful? Because we can manipulate them as we need! What would be of the human race without manipulating everything around, right?!

But how does that Class definition is applied to Objects? Well, when you create a new object it comes with some data. You are instantiating a new Object from a specific Class. You can call this object’s data as attributes. You can define them in your initialize method (a special Class method), for example.

You can really manipulate them to your needs with the functions associated with its Class. You can call them instance methods. Now let’s create a simple Class to see this in action.

So instance and objects are pretty much the same, it’s up to you how you wanna call it 🙂

Show me the code

We are going to create animal instances from the Animal Class (you can also see the code on GitHub). But before diving into the code, let’s think about the implementation a little. Let’s say we need to create an Animal Class so it’s easier to create a lot of cute animals to play with.

What does an animal have? What does it do? (We don’t need to think about everything now, we can always add/remove any information about our classes whenever we want).

We know that animals have a name, an age, a weight and a date of vaccination. These are the attributes. We also know that animals need annual vaccination, sleeping and playing. These are the object/instance methods. We’ll write a method to check if the animal has taken its vaccines, so if a new animal with outdated vaccination is created, we’ll get an alert.

We can put this into a file called animal.rb:

class Animal
  # The initialize method is a special Class method.
  def initialize(name:, age:, weight:, last_vaccine_year:)
    @name = name
    @age = age
    @weight = weight
    @last_vaccine_year = last_vaccine_year
  end

  def is_vaccinated?
     current_year = Time.now.year
     return true if current_year - last_vaccine_year <= 1
     "#{name} has not been vaccinated this year yet"
  end
end

What’s next

This simple Animal Class works fine, but it’s pretty generic, don’t you think?. What if I want to have cats, dogs, birds, fishes, horses…? I am going to need to think of Classes like Species in Biology… cool, right? But that will be our next subject when we will discuss Inheritance and Encapsulation.

If you have any questions or want to suggest/contribute feel free to comment here. I am learning Ruby as well, so any suggestion is welcome. See you soon!