Objective |
---|
To be able to create simple classes and methods |
Prev Work:
- Common Datatypes
# We want a method that splits an array on an index and | |
# removes everything afterward | |
# Example: myArray = [1, 2, 3, 4, 5, 6] | |
# splice(3, myArray) => [1,2,3,4] | |
myArray = [1,2,3,4,5,6] | |
puts "Give my an index" | |
index = gets.chomp().to_i |
# User list holds a list of names | |
# and their shopping items | |
# Expecting [name, [item1, item2]] style | |
user_list = [] | |
# Prompting the user if they want to start | |
puts "Would you like to start a nested list?[y/n]" | |
response = gets.chomp |
my_hash = {"jackie"=>"I like bowling", "Luke"=>"likes riding his bike", "imogen"=>"I have a cold", "sara"=>"I ride bart"} | |
puts "Want to start a hash?" | |
response = gets.chomp | |
while response == "y" | |
puts "Give us your name" | |
key = gets.chomp |
class Person | |
def initialize(name="no name") | |
@name = name | |
end | |
# Set method it | |
def name=(other_name) | |
@name = other_name |
class Person | |
attr_reader :name, :age | |
def initialize(name="no name", age) | |
@name = name | |
@age = age | |
end |