This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Screencast #20 | |
| class Person | |
| attr_reader :age, :occupation, :mood | |
| def initialize(age) | |
| @age = age | |
| if @age < 19 | |
| @occupation = "student" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Screencast #19 | |
| class Person | |
| def initialize(age) | |
| @age = age | |
| if @age < 19 | |
| @occupation = "student" | |
| @mood = "carefree" | |
| else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Screencast #18 | |
| class Person | |
| def start | |
| @age = 18 | |
| @occupation = "student" | |
| @mood = "carefree" | |
| return "good luck!" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Screencast #17 | |
| class Calculator | |
| def double(number) | |
| number * 2 | |
| end | |
| def add(number1, number2) | |
| number1 + number2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Screencast #16 | |
| class Cook | |
| def gather_ingredients | |
| "ingredients" | |
| end | |
| def chop | |
| gather_ingredients.reverse! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Screencast #15 | |
| class Dog | |
| def speak | |
| puts "Woof!" | |
| end | |
| def chew_on_bone | |
| puts "Mmmmm...." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| i_people_and_their_emails | |
| people = [ | |
| { | |
| "first_name" => "Bob", | |
| "last_name" => "Jones", | |
| "hobbies" => ["basketball", "chess", "phone tag"] | |
| }, | |
| { | |
| "first_name" => "Molly", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| h_people_and_their_hobbies | |
| people = [ | |
| { | |
| "first_name" => "Bob", | |
| "last_name" => "Jones", | |
| "hobbies" => ["basketball", "chess", "phone tag"] | |
| }, | |
| { | |
| "first_name" => "Molly", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| g_flatten | |
| array = [["a", "b", "z"], ["c", "d"], ["e", "f"], ["g", "h", "i", "j"]] | |
| new_array = [] | |
| array.each do |global_array| | |
| global_array.each do |letter| | |
| new_array << letter | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| f_fibonacci_numbers | |
| puts "The first 100 Fibonacci numbers are:" | |
| num_array = [0, 1] | |
| 98.times do |index| | |
| num_array << (num_array[index + 1] + num_array[index]) | |
| end |
NewerOlder