DEV Community

Mariusz Bialobrzeski
Mariusz Bialobrzeski

Posted on

Flatiron School Software Development - Phase 3 Recap

I am returning with another installment of the full stack web dev phase overview. These four weeks transitioned the content from front end to back end. The infrastructure chosen for this phase consisted of ruby, SQL (sqlite), Active Record, Rake (for db migrations) and Sinatra. Let's start with Ruby. My professional experience revolved around static languages of .Net and Java and it was cool. What can I say, I like being explicit in my creations. Ruby seems to be the opposite to this and I never considered its domain to be my cup of tea. Nevertheless there are a lot of positives as well. I love the emphasis on simplicity. I feel like there is not a single unnecessary character left in the language. Working with arrays is pure bliss thanks to a ton of short array methods that seem to be able to accomplish everything. Adding an element to an array is as simple as:

todays_menu << banana_basil_smoove
Enter fullscreen mode Exit fullscreen mode

How cool is that!

Ok. Enough with personal memoires. Let's get technical.

Here is how to build string literals:

"#{$evil_monster} is trying to kidnap Princess Peach!"
Enter fullscreen mode Exit fullscreen mode

Common debugger is pry.
Install
gem install pry
Reference

require 'pry'
Enter fullscreen mode Exit fullscreen mode

Use

binding.pry
Enter fullscreen mode Exit fullscreen mode

Looping is short and simple

10.times do |i|
  puts "Looping!"
  puts "i is: #{i}"
end
Enter fullscreen mode Exit fullscreen mode

Objects

Use @ symbol to make instance variable without declaring it anywhere.

class Dog
  def name=(value)
    @name = value
  end
end
Enter fullscreen mode Exit fullscreen mode

Attribute accessor macros
Use auto-implemented properties whenever possible for convenience and clarity

class Person
  attr_writer :name
  attr_reader :name
  attr_accessor :age
end
Enter fullscreen mode Exit fullscreen mode

Initializer methods or constructor

class Dog
  attr_reader :breed

  def initialize(breed)
    @breed = breed
  end
end
Enter fullscreen mode Exit fullscreen mode

self is equivalent to .Net's this.

  def get_adopted(owner_name)
    self.owner = owner_name
  end
Enter fullscreen mode Exit fullscreen mode

self used on method definition makes an equivalent of a static method and @@ makes a static variable in .Net

  def self.count
    @@album_count
  end
Enter fullscreen mode Exit fullscreen mode

To make a method private use private

  private

  def choose_liquor
    @cocktail_ingredients << "whiskey"
  end
Enter fullscreen mode Exit fullscreen mode

Inheritance

class Car < Vehicle

end
Enter fullscreen mode Exit fullscreen mode

To invoke code from inherited class use super.

class User

  def log_in
    @logged_in = true
  end
end

class Student < User
  def log_in
    super
    @in_class = true
  end
end
Enter fullscreen mode Exit fullscreen mode

Top comments (0)