Ruby Monstas Session 13 Agenda Recap Class Methods & Class - - PowerPoint PPT Presentation

ruby monstas
SMART_READER_LITE
LIVE PREVIEW

Ruby Monstas Session 13 Agenda Recap Class Methods & Class - - PowerPoint PPT Presentation

Ruby Monstas Session 13 Agenda Recap Class Methods & Class Variables Time (Standard Library) Exercises Recap Recap: Classes and Objects class Customer irb> beat = Customer.new(1, Beat) =>


slide-1
SLIDE 1

Ruby Monstas

Session 13

slide-2
SLIDE 2

Agenda

Recap Class Methods & Class Variables Time (Standard Library) Exercises

slide-3
SLIDE 3

Recap

slide-4
SLIDE 4

Recap: Classes and Objects

class Customer def initialize(id, name) @id = id @name = name end def id @id end def name @name end end irb> beat = Customer.new(1, “Beat”) => #<Customer:0x007f8b8289a868> irb> beat.id => 1

slide-5
SLIDE 5

Recap: CSV

CSV_DELIMITER = ";" csv = File.read('customers.csv') lines = csv.split("\n") lines.each do |line| parts = line.split(CSV_DELIMITER) id = parts[0] first_name = parts[1] last_name = parts[2] location = parts[3] end 1;Peter;Parker;New York 2;Steven;Miller;New York 3;Milo;Jehle;Zurich 4;Daron;Treadaway;Zurich 5;Darrick;Flakes;Zurich 6;Susan;Mckenna;Zurich 7;Catarina;Keating;Zurich 8;Ira;Whitsett;Zurich

slide-6
SLIDE 6

Class Methods & Class Variables

slide-7
SLIDE 7

Class Methods & Class Variables

class Customer @@all = [] def initialize(id, name) @id = id @name = name @@all.push(self) end def self.all @@all end … end irb> beat = Customer.new(1, “Beat”) => #<Customer:0x007f8b8289a868> irb> Customer.all.count => 1 irb> Customer.all.first.name => “Beat”

slide-8
SLIDE 8

Time

Standard Library

slide-9
SLIDE 9

Time

irb> time = Time.new => 2015-09-12 16:15:35 +0200 irb> time.year => 2015 irb> time.month => 09

slide-10
SLIDE 10

Time

irb> time.day => 12 irb> time.wday => 6 irb> time.yday => 255

slide-11
SLIDE 11

Time

irb> time.strftime("%d.%m.%Y %H:%M:%S") => "12.09.2015 16:15:35" irb> time - 10 => 2015-09-12 16:15:35 +0200 irb> time.utc => 2015-09-12 14:15:35 +0200 UTC

slide-12
SLIDE 12

Resources

Ruby Classes http://ruby-doc.org/core-2.2.0/Class.html Time (Standard Library) http://ruby-doc.org/stdlib-2.2.3/libdoc/date/rdoc/Time.html

slide-13
SLIDE 13

Time to practice

TodoList Exercise: https://github.com/rubymonstas-zurich/todolist-exercise