Skip to content

Instantly share code, notes, and snippets.

@amy-mac
Created September 29, 2013 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amy-mac/3a811124a1fcd88a4ed1 to your computer and use it in GitHub Desktop.
Save amy-mac/3a811124a1fcd88a4ed1 to your computer and use it in GitHub Desktop.
Blender homework for WDI - Week One
# Instructions are written inline.
# docs you may enjoy
# http://www.ruby-doc.org/core-2.0/Hash.html
# http://ruby-doc.org/core-2.0/String.html
# http://ruby-doc.org/core-2.0/Array.html
# Every Morning I make a smoothie with the follow ingredients:
smoothie_recipe = {
'flax seeds' => '1 tbsp',
'chia seeds' => '1 tbsp',
'coconut flakes' => '1 tbsp',
'spirulina' => '1 tsp',
'pumpkin seeds' => '1 tbsp',
'oatmeal' => '1/4 cup',
'coco powder' => '1 tbsp',
'peanut butter' => '1 tbsp',
'almonds' => '1/4 cup',
'walnuts' => '1/4 cup',
'spinach' => '1/4 cup',
'greek yogurt' => '1/4 cup',
'nutrional yeast' => '1 tbsp',
'brussel sprouts' => '1/4 cup',
'asparagus' => '1/4 cup',
'kale' => '1/4 cup',
'brocoli rabe' => '1/4 cup',
'blueberries' => '1/4 cup',
'chopped banana' => '1/2 cup',
'strawberries' => '1/4 cup',
'mango' => '1/4 cup',
'hemp milk' => '1 cup'
}
# Write a function called blend.
# It should take all the smoothie ingredients (not the measurements) and chop up and mix all the characters
# and output a mixed string of characters
# Be sure to remove the spaces, as we don't want any air bubbles in our smoothie!
def blend(smoothie_ingredients)
ingredients = smoothie_ingredients.keys.join
ingredients = ingredients.split(//) - [' ']
ingredients = ingredients.shuffle.join
p ingredients
end
blend(smoothie_recipe)
# create a class called Blender
# It should have a method that takes an array of ingredients and returns a mixed string of characters.
# Give the blender an on and off switch and only allow the blender to function when it's on.
# FOR SAFETY'S SAKE When you create a new blender by default it should be off.
# Blend the the smoothie array
class Blender
attr_accessor :ingredients, :switch
def initialize(ingredients)
@ingredients = ingredients
@switch = 'off'
end
def flip_switch
@switch = 'on'
puts 'You have turned the blender on.'
end
def blend
if @switch == 'on'
@ingredients = @ingredients.join('')
@ingredients = @ingredients.split('') - [' ']
@ingredients = @ingredients.shuffle.join('')
puts 'You are finished blending.'
puts "Here is your string: #{@ingredients}"
else
puts 'Sorry, the blender is currently off.'
end
end
end
morning_shake = Blender.new(['beer', 'gooey stuff', 'milk', 'peanut butter'])
morning_shake.blend
morning_shake.flip_switch
morning_shake.blend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment