ruby monstas
play

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) =>


  1. Ruby Monstas Session 13

  2. Agenda Recap Class Methods & Class Variables Time (Standard Library) Exercises

  3. Recap

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

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

  6. Class Methods & Class Variables

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

  8. Time Standard Library

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

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

  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

  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

  13. Time to practice TodoList Exercise: https://github.com/rubymonstas-zurich/todolist-exercise

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend