Skip to content

Instantly share code, notes, and snippets.

@RedSoxFan22
RedSoxFan22 / PreWork Ruby Code
Last active August 29, 2015 14:18
Iron Yard PreWork Ruby Code
x = 1
while x <= 100
if x % 3 == 0
puts "Fizz"
elsif x % 5 == 0
puts "Buzz"
else
puts x
end
x += 1
@RedSoxFan22
RedSoxFan22 / May4.rb
Last active August 29, 2015 14:20
First assignment
puts "Please enter a number."
counter = 0
total = 0
string_total = []
while true
input = gets.chomp
if input.to_i > 0
puts "Good. How about another?"
counter += 1
def fizzbuzz (num)
if num % 3 == 0
p "Fizz"
elsif num % 5
p "Buzz"
elsif num % 3 == 0 && num % 5 == 0
p "FizzBuzz"
else
return num
end
require 'minitest/autorun'
require 'minitest/pride'
require './names.rb'
def names(president)
array = []
hash = {}
input = gets.chomp.to_s
array << input
require 'minitest/autorun'
require 'minitest/pride'
require './may.rb'
class Goat
attr_reader :name
def initialize(name)
end
def send(message)
require 'minitest/autorun'
require 'minitest/pride'
require './may.rb'
# Write two classes which inherit from the Vehicle class below. You will also
# need to add a method to the Vehicle class during this challenge.
class Vehicle
def initialize(make, model)
@make = make
@model = model
require 'minitest/autorun'
require 'minitest/pride'
require './array.rb'
class OddArray
def initialize(array)
@array = array
end
def to_a
require 'minitest/autorun'
require 'minitest/pride'
require './may26.rb'
class Array
def initialize
end
def has_even?(array)
num.map{|n| n % 2 == 0}
require 'minitest/autorun'
require 'minitest/pride'
require './may1.rb'
module Intelligent
NUMBER_OF_LEGS = 2
NUMBER_OF_BRAINS = 1
class Human
def say_name
puts "My name is #{@name}."
An array and a hash are both collections of data. While an array is written with brackets [], a ahsh is written with curly braces {}. In an array, each piece of data is in a particular place, or index, withn the array. The indexes begin at 0. To get an particualr item from an array, one calls the name of the array and the index on the item like this: array[index_number]. Hashes are often referred to as dictionaries because each spot in a has contains two things, one (the key) refers to the other (the value). To get a particular item from a hash, one calls the name of the hash and uses the key to retrieve the item. There are also different methods available to arrays and hashes. Array methods incluede .each, .map, .select., .join, etc.
A string can be an type of text that is encolsed within quotes. A symbol is the key element in a hash. A symbol is a more powerful tool because it can be used as an attr_accessor within a program, or as a parameter in an initiliazed method. Thus is can be passed ar