ACING THE FIRST SOFTWARE ENGINEERING CODE CHALLENGE: AT FLATIRON SCHOOl

Get a quick overview of where you need a firm understanding for the code challenge.

I think you’ll agree with me when I say :

It can be REALLY hard to dive into the field of software engineering , if you have no prior coding experience. This could be almost relatable to talking to an alien! Exactly my point…we don’t know what that would be like either.

But imagine being able to explore the new realms of reality, and conquer them!

Through this post you will get a brief overview of what you need to know for the first code challenge at flatiron school.

CONTENTS::

<<Ruby Object Methods>>

<<Ruby Data Types>>

<<Ruby EACH Method>>

<<For and While loop>>

<<Object Oriented Programming>>

<<Ruby Block Parameter>>

<<QuickQuizz>>

RUBY OBJECT METHODS

var = “flatiron”

# Method to get the length of a string

print var.length # 8

# Method to get the string reversed

print var.reverse # noritalf

# Method to convert all letters to uppercase

print var.upcase # FLATIRON

  • **In Ruby, methods are built-in abilities of objects. To access an object’s methods, you need to call it using a . and the method name.

DATA TYPES IN RUBY

NUMERIC DATA TYPES

# Integer value

x = 1

# Float value

y = 1.2

***In Ruby, the Numeric data type represents numbers including integers and floats.

BOOLEAN DATA TYPES

year2020 = true

# Boolean false variable

year2019 = false

  • #In Ruby, in order to represent values of truth about specific statements, we use Boolean variables. Boolean variables values are either true or false.

Ruby each Method

To iterate over an array in Ruby, use the .each method. It is preferred over a for loop as it is guaranteed to iterate through each element of an array.

Also, refer to other methods such as .map, .select, .collect and more here.

Ruby for Loop

A block of code can be repeated a set amount of times with the for loop in Ruby.

Ruby while Loop

Putting a block of code in a while loop in Ruby will cause the code to repeatedly run the code as long as its condition is true.

If the block of code doesn’t have a way for the condition to be changed to false, the while loop will continue forever and cause an error.

OO PROGRAMMING:

Ruby Class

class NewClass

# code for this class

end

# A basic class definition consists of the class keyword, the name of the class in CamelCase (with the first letter capitalized) format, and an end keyword.

A Ruby class is used to organize and model objects with similar attributes and methods.

Ruby Instance Variable

class Puppy

def initialize(name, age)

@name = name

@age = age

end

end

# In this example, name and age are the instance variables.

In Ruby, the @ symbol is used to signify an instance variable. Instance variables hold a value specific to each instance of that class, not to all members of the class itself.

Ruby initialize Method

class Person

def initialize

# this code runs when a new instance is created

end

end

#Every time Person.new is called, the initialize method of the Person class is called.

In a Ruby class, an initialize method is used to generate new instances of the class. It is usually the first method of a class.

Ruby Class Variables

class Child

@@children = 0

def initialize(name, birth_year)

@name = name

@birth_year = birth_year

@@children +=1

end

def self.children_added

return @@children

end

end

naomi = Child.new(“Naomi”, 2006)

bertha = Child.new(“Bertha”, 2008)

puts Child.children_added # => 2

In Ruby, class variables are attached to the class in which they are declared. A class variable should be declared with two @ symbols preceding it.

**Ruby attr_accessor Method

class CollegeStudent

attr_reader :dorm

attr_accessor :major

def initialize(dorm, major)

@dorm = dorm

@major = major

end

end

#In this example, Ruby is able to only read the @dorm instance variable but both read and write the @major instance variable since it was passed to the attr_accessor method.

In Ruby, attr_accessor, used to make a variable both readable and writeable, is a shortcut to attr_reader and attr_writer.

Ruby Block Parameter

# The block, {|i| puts i}, is passed the current array item each time it is evaluated. This block prints the item.

[1, 2, 3, 4, 5].each { |i| puts i }

In Ruby, a method can take a block as a parameter.

Passing a block to a method is a great way of abstracting certain tasks from the method and defining those tasks when we call the method.

The above contents should not be the sole reference before the code challenge, however you may refer to it as a guidance and for a quick overview.

Now let’s see what we’ve learnt…

Take The Quiz

Software Engineer | Day Dreamer | Get Better by the Day