Skip to content

Instantly share code, notes, and snippets.

View scarow's full-sized avatar

Sam Carow scarow

  • Los Angeles, CA
View GitHub Profile
@scarow
scarow / gist:5897043
Last active December 19, 2015 04:28
Create a GuessingGame class which is initialized with an integer called answer. Define an instance method GuessingGame#guess which takes an integer called guess as its input. guess should return the symbol :high if the guess is larger than the answer, :correct if the guess is equal to the answer, and :low if the guess is lower than the answer. D…
class GuessingGame
def initialize(answer)
@answer = answer
end
def guess(num_guessed)
@num_guessed = num_guessed
if @num_guessed > @answer
@scarow
scarow / gist:5896176
Last active December 19, 2015 04:19
Exercise: Create a method to pad an array Implement Array#pad and Array#pad!. Each method accepts a minimum size (non-negative integer) and an optional pad value as arguments. If the array's length is less than the minimum size, Array#pad should return a new array padded with the pad value up to the minimum size. For example, ruby [1,2,3].pad(5)…
class Array
def pad!(min_size, value = nil)
length = self.length
size = min_size - length
if min_size <= length
return self
end