Skip to content

Instantly share code, notes, and snippets.

@vin-droid
Last active April 24, 2020 19:18
Show Gist options
  • Select an option

  • Save vin-droid/15dbc4551f92897e1dd602fb0416d8cc to your computer and use it in GitHub Desktop.

Select an option

Save vin-droid/15dbc4551f92897e1dd602fb0416d8cc to your computer and use it in GitHub Desktop.

ruby-training-plan

Plan for a training on Ruby language to new interns

Day's Schedule:

  • 2-3 hours of interactive training
  • Rest of the day:
    • few questions related to what was taught
    • a coding assignment
    • the interns will interact with their mentors throughout the day

For each topic:

  • subjective questions
  • coding assignments

Topics:

  • installation of ruby, git
  • git basics
  • ruby intro:
    • why ruby?
    • features of ruby
    • ruby vs other languages
    • rvm
  • vim
  • ruby style guidelines
  • operators
  • variables
  • data types
  • methods, return not needed on last line,
  • control statements
  • loops, iterations, methods like map, select
  • exception handling
  • gems, gemsets, creating a gem
  • debugging code (usin pry)
  • rubocop
  • block, proc, lambda
  • object oriented concepts
    • why OOPS?
    • a little revision on concepts
    • classes and objects:
      • instance/class vaiables/methods
      • accessor methods
      • self keyword
      • public, private, protected methods
    • inheritance
    • modules:
      • mixins
      • namespacing

https://launchschool.com/books/ruby/read/

Intro:

  • It emphasizes the necessity for software to be understood by humans first and computers second.
  • a high level language
  • interpreted language
  • Ruby abstracts away (i.e. handles for you) most of the complex details of the machine
  • flexibility
  • performance (why it is slower)
  • everything is an object

Style guidelines:

  • indenting: 2 spaces for a tab
  • variable and method names: use snake_case
  • CONSTANT declarations
  • ClassName: CamelCase
  • single line and multiline blocks
  • string '' cs ""

Strings:

  • interpolation
  • escape chars

Symbols

Numbers:

  • int, float

Boolean

nil:

  • nothing

Operators:

      • / % == === < > && || !

Type conversion: to_i, to_s etc

Data Strictures:

  • Array
  • Hash
    • see different methods
    • sequence?

Variables:

  • assigninig values

  • CONSTANTS

  • $global_variables

  • scope of variables

Methods:

  • why?
  • how in ruby
  • params, arguments
  • default arguments
  • variable scope in methods
  • method chaining
  • methods as arguments?

Conditionals:

  • if else unless
  • ternary
  • switch case

Questions:

  • Difference between "string" and "symbol" in ruby?

  • What is "nil" in ruby, is it an object?

  • Difference between "nil" and empty string ""?

  • Difference between "==" and "==="

  • Difference between single quote and double quote

  • [ a = "hi there" b = a a = "not here" puts b ]

    [ a = "hi there" b = a a << ", Bob" puts b ]

    • what is the value of b printed in each of the above?
    • why?

Ruby: Day 2

  • prev day assignments

  • revision of day 1

  • what anyone learnt new that wasn't taught

  • comparing two hashes?

  • other ways to create a Hash/Array

    • using new keyword
  • scopes of variables

  • global variables

  • default params for a method

  • methods as arguments?

  • variable number of parameters for a method (*)

  • undef method

  • Range in ruby:

    • use to_a method
    • as sequences:

      digits = 0..9 puts digits.include?(5) ret = digits.min digits.each {|n| puts n }
    • as conditions: case when 0..30
    • as intervals (1..10) === 5
  • loops in ruby

    • while do...end
    • begin..end while
    • until do..end
    • for in for num in 1..5 { num }
    • break and next statements
    • each do..end
  • extra Array methods:

    • sort
    • select
    • collect a = [1,2,3,4,5] b = a.collect{|x| 10*x}
    • map
  • extra Hash methods:

    • clear, delete, each, each_key, empty?, has_value?(value), inverse, keys, merge, merge!, reject, select, sort, to_a,
  • blocks in ruby

    • passing a block to a method (a block that accepts params)
    • calling the block in the method using yield
      • def test yield end test { puts "Hello world"}
    • other way to call the block in the method
      • def test(&block) block.call end test { puts "Hello World!"}`
  • Exceptions: begin
    # -
    rescue OneTypeOfException
    # -
    rescue AnotherTypeOfException
    # -
    else
    # Other exceptions ensure # Always will be executed end

  • inheritance: (IS-A)

    • overriding
    • super keyword
    • private methods
    • protected methods
  • modules: (HAS-A)

    • why?

    • including

    • extending

    • no instantiation

    • order of including modules important?

    • a way to achieve multiple inheritance?

    • the diamond problem

    • namespacing: (organizing similar classes in a module)

      • defining classes inside a module

Sample Conceptual questions to be asked:

(Questions that may need some exploring on their own)

  • Difference between "string" and "symbol" in ruby?

  • What is "nil" in ruby, is it an object?

  • Difference between "nil" and empty string ""?

  • Difference between "==" and "==="

  • Difference between single quote and double quote

  • How can we access/set value for a variable which is declared inside class but outside every method...????

  • In Ruby, if a class itself is an object, then how can we access the properties/attributes of that object..???

  • Can we create nested modules..?? If yes, then how they can be used..?? Study the syntaxes...

  • How can we access the CONSTANTS declared inside Module or Class, outside Module/Class...????

  • Differentiate between block, proc and lambda, when to use which.

  • [ a = "hi there" b = a a = "not here" puts b ]

    [ a = "hi there" b = a a << ", Bob" puts b ]

    • what is the value of b printed in each of the above?
    • why?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment