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
class Animal | |
def initialize(name) | |
@name = name | |
end | |
def eat(food) | |
puts "#{@name} the #{self.class} eats #{food}." | |
end | |
def emote |
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
class HomePurchaseOption | |
attr_reader :address, :property_value, :selling_price, :down_payment | |
def initialize(attributes) | |
@address = attributes[:address] | |
@property_value = attributes[:property_value] | |
@selling_price = attributes[:selling_price] | |
@down_payment = attributes[:down_payment] | |
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 'benchmark' | |
tax_records = [ | |
{ | |
first_name: 'Johnny', | |
last_name: 'Smith', | |
annual_income: 120000, | |
tax_paid: 28000 | |
}, | |
{ |
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
salutations = [ | |
'Mr.', | |
'Mrs.', | |
'Mr.', | |
'Dr.', | |
'Ms.' | |
] | |
first_names = [ | |
'John', |
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
class Circle | |
# attr_accessor :radius | |
def initialize(radius) | |
@radius = radius.to_i | |
end | |
def diameter | |
@diameter = @radius * 2 |
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
class Card | |
def initialize(rank = nil, suit = nil) | |
if suit.nil? | |
@suit = ['♠', '♣', '♥', '♦'].sample | |
else | |
@suit = suit | |
end | |
@rank = [2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A'].sample | |
puts "Create a new card: #{@rank} of #{@suit}" | |
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
#!/usr/bin/env ruby | |
require 'pry' | |
fruits =["pineapple", "kiwi" , "peach" , "pear" , "guava" , "strawberry" , "banana" , "lemon" , "watermelon"] | |
word = fruits.sample | |
guesses = 8 | |
hidden = "_" * word.length | |
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
number = rand(0...100) | |
puts "Let's play a game!" | |
print "Guess a number between 0 and 100:" | |
loop do | |
guess = gets.chomp | |
if !/^\d+$/.match(guess) | |
puts 'Invalid guess, try again...' | |
print "guess again: " |
NewerOlder