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
# must be baller and either furnished or rent cheaper than 2100 | |
def rent?(furnished, rent, baller) | |
#if baller && furnished || rent < 2100 | |
if baller && (furnished || rent < 2100) | |
return true | |
else | |
return false | |
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
def sum(list) | |
sum = 0 | |
list.each do |num| | |
sum += num | |
end | |
sum | |
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 benchmark | |
# Your benchmarking code goes here. | |
start_time = Time.now | |
yield | |
end_time = Time.now | |
running_time = end_time - start_time | |
end | |
# Be careful, pasting this into IRB will take a long time to print. | |
# It's a loooong string. :) |
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
# Determine whether a string contains a SIN (Social Insurance Number). | |
# A SIN is 9 digits and we are assuming that they must have dashes in them | |
#rescue Exception => e | |
#end | |
def has_sin?(string) | |
/^.\w*\s\w*.t\s\w*\s[s-u]\D{3}.\s234\W6?0?4?.(142)[^1,]$/ === string |
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
@states = { | |
OR: 'Oregon', | |
FL: 'Florida', | |
CA: 'California', | |
NY: 'New York', | |
MI: 'Michigan', | |
TX: 'Texas', | |
AL: 'Alaska' | |
} |
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
# Save this file to your computer so you can run it | |
# via the command line (Terminal) like so: | |
# $ ruby shakil_the_dog.rb | |
# | |
# Your method should wait for user input, which corresponds | |
# to you saying something to your dog (named Shakil). | |
# You'll probably want to write other methods, but this | |
# encapsulates the core dog logic | |
def shakil_the_dog |
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
# Find the maximum | |
def maximum(arr) | |
max = arr[0] | |
arr.each do |child| | |
if child > max | |
max = child | |
end | |
end | |
max |
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 Animal | |
attr_reader :height , :habitat | |
def initialize(height, habitat) | |
@height = height | |
@habitat = habitat | |
end | |
def wakeup (wakeup_sound) | |
puts " i make this sound #{wakeup_sound} when I wakeup" |
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
require_relative 'contact' | |
# Interfaces between a user and their contact list. Reads from and writes to standard I/O. | |
class ContactList | |
# TODO: Implement user interaction. This should be the only file where you use `puts` and `gets`. | |
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
#two player maths game using objects | |
# defining the player class | |
class Player | |
attr_accessor :name, :number_of_lives | |
def initialize (name) | |
@name = name | |
@number_of_lives= 3 | |
end |
OlderNewer