Last active
August 29, 2015 14:20
-
-
Save utumno86/f42adb4abd4b0e420c2a to your computer and use it in GitHub Desktop.
Day One Assignment Iron Yard
This file contains 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
# 1. Assign "Hello World" to a variable message. | |
message = "Hello World" | |
# 2. Assign a different string to a different variable. | |
x = "different string" | |
# 3. Assign a number to a variable. | |
num = 3 | |
# 4. Use string interpolation to display the number from exercise 3 in a string. | |
num_string = "This is a string with the number #{num} in it" | |
puts num_string | |
# 5. Make an array of at least four of your favorite movies or books or bands. | |
fav_books = ["The Once and Future King", "The Sandpebbles", "Steppenwolf", "Wonder Boys"] | |
puts fav_books | |
# 6. Make a hash of information about yourself with at least four key-value pairs. | |
me = { name: "Michael", age: 28, eye_color: "grey", beard: "straggly"} | |
#7. Make an array of hashes containing more information about your favorite movies. The hashes should have at least three key value pairs. | |
fav_movies = [ | |
{title: "The Maltese Falcon", actor: "Humphrey Bogart", decade: "1940s?"}, | |
{title: "Batman Returns", actor: "Michael Keaton", decade: "1980s?"}, | |
{title: "Iron Man", actor: "Robert Downey Jr.", decade: "2000s"} | |
] | |
#8. Use `each` to loop through the answer from exercise #7 and print only one property from the hash. i.e., given `{ title: "Gone with the Wind" }` you print "Gone with the Wind". | |
fav_movies.each {|x| puts x[:title]} |
This file contains 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
# 1. Assign "Hello World" to a variable message. | |
message = "Hello World" | |
# 2. Assign a different string to a different variable. | |
x = "different string" | |
# 3. Assign a number to a variable. | |
num = 3 | |
# 4. Use string interpolation to display the number from exercise 3 in a string. | |
num_string = "This is a string with the number #{num} in it" | |
puts num_string | |
# 5. Make an array of at least four of your favorite movies or books or bands. | |
fav_books = ["The Once and Future King", "The Sandpebbles", "Steppenwolf", "Wonder Boys"] | |
puts fav_books | |
# 6. Make a hash of information about yourself with at least four key-value pairs. | |
me = { name: "Michael", age: 28, eye_color: "grey", beard: "straggly"} | |
#7. Make an array of hashes containing more information about your favorite movies. The hashes should have at least three key value pairs. | |
fav_movies = [ | |
{title: "The Maltese Falcon", actor: "Humphrey Bogart", decade: "1940s?"}, | |
{title: "Batman Returns", actor: "Michael Keaton", decade: "1980s?"}, | |
{title: "Iron Man", actor: "Robert Downey Jr.", decade: "2000s"} | |
] | |
#8. Use `each` to loop through the answer from exercise #7 and print only one property from the hash. i.e., given `{ title: "Gone with the Wind" }` you print "Gone with the Wind". | |
fav_movies.each {|x| puts x[:title]} |
This file contains 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
class Robot | |
def initialize(name) | |
@name=name | |
end | |
def say_hi | |
puts "Hi!" | |
end | |
def say_name | |
puts "My name is #{@name}" | |
end | |
end | |
robotIV = Robot.new("Prince Robot IV") | |
robotIV.say_hi | |
robotIV.say_name | |
#Define a Robot class | |
#A robot should have a name. | |
#A robot should have a method called say_hi and it should return "Hi!" | |
#A robot should have a method called say_name and it should return "My name is X" where X is the robot's name. | |
#Create an instance of your robot and add some demonstrations of your it's features at the end of the file. | |
#Bonus | |
#Define a new type of robot that inherits from your first Robot class. | |
#Have your new robot class do say_name in a different way than the original. | |
#Add some demonstrations of your new robot's features at the end of the file as well. | |
#Close this issue to notify me for review. Be sure to include a link to your solution. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment