This file contains hidden or 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
| x = 1 | |
| while x <= 100 | |
| if x % 3 == 0 | |
| puts "Fizz" | |
| elsif x % 5 == 0 | |
| puts "Buzz" | |
| else | |
| puts x | |
| end | |
| x += 1 |
This file contains hidden or 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
| puts "Please enter a number." | |
| counter = 0 | |
| total = 0 | |
| string_total = [] | |
| while true | |
| input = gets.chomp | |
| if input.to_i > 0 | |
| puts "Good. How about another?" | |
| counter += 1 |
This file contains hidden or 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 fizzbuzz (num) | |
| if num % 3 == 0 | |
| p "Fizz" | |
| elsif num % 5 | |
| p "Buzz" | |
| elsif num % 3 == 0 && num % 5 == 0 | |
| p "FizzBuzz" | |
| else | |
| return num | |
| end |
This file contains hidden or 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 'minitest/autorun' | |
| require 'minitest/pride' | |
| require './names.rb' | |
| def names(president) | |
| array = [] | |
| hash = {} | |
| input = gets.chomp.to_s | |
| array << input |
This file contains hidden or 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 'minitest/autorun' | |
| require 'minitest/pride' | |
| require './may.rb' | |
| class Goat | |
| attr_reader :name | |
| def initialize(name) | |
| end | |
| def send(message) |
This file contains hidden or 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 'minitest/autorun' | |
| require 'minitest/pride' | |
| require './may.rb' | |
| # Write two classes which inherit from the Vehicle class below. You will also | |
| # need to add a method to the Vehicle class during this challenge. | |
| class Vehicle | |
| def initialize(make, model) | |
| @make = make | |
| @model = model |
This file contains hidden or 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 'minitest/autorun' | |
| require 'minitest/pride' | |
| require './array.rb' | |
| class OddArray | |
| def initialize(array) | |
| @array = array | |
| end | |
| def to_a |
This file contains hidden or 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 'minitest/autorun' | |
| require 'minitest/pride' | |
| require './may26.rb' | |
| class Array | |
| def initialize | |
| end | |
| def has_even?(array) | |
| num.map{|n| n % 2 == 0} |
This file contains hidden or 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 'minitest/autorun' | |
| require 'minitest/pride' | |
| require './may1.rb' | |
| module Intelligent | |
| NUMBER_OF_LEGS = 2 | |
| NUMBER_OF_BRAINS = 1 | |
| class Human | |
| def say_name | |
| puts "My name is #{@name}." |
This file contains hidden or 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
| An array and a hash are both collections of data. While an array is written with brackets [], a ahsh is written with curly braces {}. In an array, each piece of data is in a particular place, or index, withn the array. The indexes begin at 0. To get an particualr item from an array, one calls the name of the array and the index on the item like this: array[index_number]. Hashes are often referred to as dictionaries because each spot in a has contains two things, one (the key) refers to the other (the value). To get a particular item from a hash, one calls the name of the hash and uses the key to retrieve the item. There are also different methods available to arrays and hashes. Array methods incluede .each, .map, .select., .join, etc. | |
| A string can be an type of text that is encolsed within quotes. A symbol is the key element in a hash. A symbol is a more powerful tool because it can be used as an attr_accessor within a program, or as a parameter in an initiliazed method. Thus is can be passed ar |
OlderNewer