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 List | |
def initialize(title) | |
@list = [] | |
@title = title | |
end | |
def append(item) | |
if item.is_a?(Item) | |
@list << item |
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
def translate(word) | |
if word[0] == "a" || word[0] == "e" || word[0] == "i" || word[0] == "o" || word[0] == "u" | |
word << "ay" | |
elsif word[0..1] == "qu" | |
f = (word[0..1] << 'ay') | |
word[0..1] = "" | |
word << f |
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
def triangle(num1,num2,num3) | |
if num1 >= num2 + num3 || num2 >= num1 + num3 || num3 >= num2 + num1 | |
:invalid | |
elsif num1 == num2 && num2 == num3 && num3 == num1 | |
:equilateral | |
elsif num1 == num2 || num2 == num3 || num3 == num1 | |
:isosceles | |
elsif num1 != num2 && num2 != num3 && num3 != num1 | |
:scalene | |
end |
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
def smiley(input) | |
if input[:mood] == "happy" #mood is the key, it also has to be a string | |
return ":)" | |
elsif input[:mood] == "sad" | |
return ":(" | |
else | |
return ":|" | |
end | |
end |
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 Numeric | |
def add(num) | |
self + num | |
end | |
def subtract(num) | |
self - num | |
end | |
def multiply(num) |
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
module Calculator | |
def add(num) | |
self + num | |
end | |
def subtract(num) | |
self - num | |
end | |
def multiply_by(num) |
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
Exercise 4 | |
Create a new instance method on the String class called fun_string! which is called on a String object and permanently modifies it by capitalizing the even characters (counting from 1) and then reversing the string. See if you can do it in a single line. | |
For example, | |
string = "apples" | |
string.fun_string! | |
string # now equals "SeLpPa" |
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
#Object Oriented Design, Simon Allardice from lynda.com | |
#Class: SpaceShip | |
#Attributes: +public name: String | |
# -private shieldstrength: Integer | |
#Operations: +fire( ): String | |
# -reduce shields (Integer) | |
#Notes: 1. Public Class Spaceship | |
# 2. Attributes are expressed as instance variables, which are variables that belong to an instance of a class. What this means is that any object created within this class will have their own copy of these variables <--I NEED A VISUAL OF THIS BADLY |
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
#Given a random array, create a method that sorts the array so the numbers are returned in order. | |
a= [5, 8, 3, 2, 7, 4, 1, 0, 9, 6, 10, 55] | |
#Final Answer | |
def singlesort(a) | |
(a.size - 1).times do |i| | |
if a[i] > a[i+1] | |
x=a[i] | |
a[i] = a[i+1] |
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
def make_address(street,city,state,zip) | |
"You live at #{street} in the beautiful city of #{city}, #{state}. Your zip is #{zip}." | |
end | |
make_address("6056 Plumas St.", "Reno", "NV","89519") |