Skip to content

Instantly share code, notes, and snippets.

@Ebonkuab
Ebonkuab / renter.rb
Created January 6, 2016 00:55
an exercise for checking if the bolean operation is correct for the problem being solved
# 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
@Ebonkuab
Ebonkuab / Debugging Code.RB
Created January 6, 2016 20:58
code decoded during the debugging excercise in Lighthouse Labs
def sum(list)
sum = 0
list.each do |num|
sum += num
end
sum
end
@Ebonkuab
Ebonkuab / Benchmark.rb
Created January 7, 2016 19:21
code for getting how long it takes to run a programme written in Ruby using Yield keyword and blocks . (LIGHTHOUSE WEB DEV BOOTCAMP0
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. :)
@Ebonkuab
Ebonkuab / Regular_expressions.rb
Created January 8, 2016 00:35
Using Regular expressions (Regex) to select strings to give a true with bolean operations
# 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
@Ebonkuab
Ebonkuab / State_info.rb
Created January 8, 2016 17:57
Using ruby code to access data defined in Hashes and implementing them in Methods ( LIGHTHOUSE WEB DEV BOOTCAMP)
@states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan',
TX: 'Texas',
AL: 'Alaska'
}
@Ebonkuab
Ebonkuab / shakil_the_dog.rb
Created January 8, 2016 21:05
ruby code for interaction with shakil the dog (LIGHTHOUSE DEV BOOTCAMP)
# 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
@Ebonkuab
Ebonkuab / maximum-value.rb
Last active January 9, 2016 00:52
using ruby code to get the maximum value within a one dimensional array (LIGHTHOUSE WEB DEV BOOTCAMP)
# Find the maximum
def maximum(arr)
max = arr[0]
arr.each do |child|
if child > max
max = child
end
end
max
@Ebonkuab
Ebonkuab / classical_inheritance.rb
Created January 11, 2016 22:50
using the inheritance properties of ruby to display different properties for sub-classes (LIGHTHOUSE WEB DEV BOOTCAMP)
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"
@Ebonkuab
Ebonkuab / contact_list.rb
Created January 12, 2016 18:13
Starter code for the Contact List app
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
@Ebonkuab
Ebonkuab / two_player_game.rb
Created January 12, 2016 20:56
two player guesing game using OOP ruby ( LIGHTHOUSE WEB DEV BOOTCAMP)
#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