This file contains 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 <<first | |
1 Push It, Push It Good | |
What’s the difference between these two Ruby expressions? | |
[1,2,3].push(1,2,3) | |
[1,2,3].push([1,2,3]) | |
#You can push items into an array, and it will append the original array | |
#with the new data at the end. | |
1a The first results in [1,2,3,1,2,3] adding the (1,2,3) in order to the array |
This file contains 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 "How much is the bill?" | |
bill = gets.to_f | |
puts "The bill is $#{bill}" | |
puts "How would you like to pay? Visa, Amex, Diners Club?" | |
pay = gets.chomp |
This file contains 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 "Hey Larry! That's your name right?" | |
you_Larry = gets.chomp | |
if "Yes".downcase | |
puts "I knew you were!! I would recognize that cheap suit anywhere" | |
else | |
puts "Listen here you dirty ba&^$^. You're Larry and theres nothing you can do about it!!" | |
end | |
puts <<END |
This file contains 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 "How much is the bill?" | |
bill = gets.to_f | |
puts "The bill is $#{bill}" | |
puts "How would you like to pay? Visa, Amex, Diners Club?" | |
pay = gets.chomp |
This file contains 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 "Hey Larry! That's your name right?" | |
case gets.chomp | |
when "yes".downcase | |
puts "I knew you were!! I would recognize that cheap suit anywhere" | |
else | |
puts "Listen here you dirty ba&^$^. You're Larry and theres nothing you can do about it!!" | |
end | |
puts <<END |
This file contains 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
# Add 2 to the number. | |
def add_two(number) | |
if number.respond_to? :+ | |
if number.respond_to? :push | |
number.push 2 | |
elsif number.respond_to? :squeeze | |
puts "Please enter a valid number!" | |
else | |
number + 2 | |
end |
This file contains 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 mad_max(a,b) | |
if (a.is_a? Fixnum) && (b.is_a? Fixnum) | |
puts [a,b].max | |
else | |
if a||b == String | |
puts "Please put a valid number" | |
end | |
end | |
end |
This file contains 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 mad_max(a,b, *rest) | |
if (a.is_a? Numeric) && (b.is_a? Numeric) | |
puts [a,b].max | |
else | |
puts "Please put a valid number" | |
end | |
end |
This file contains 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
(1..100).each do |n| | |
case | |
when (n % 3 == 0) && (n % 5 == 0) | |
puts "FIZZBUZZ" | |
when n % 3 == 0 | |
puts "Fizz" | |
when n % 5 == 0 | |
puts "Buzz" | |
else | |
puts n |
This file contains 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 Quadrilateral | |
attr_accessor :top, :bottom, :left, :right | |
def initialize(left, top, right, bottom) | |
@left = left | |
@top = top | |
@right = right | |
@bottom = bottom | |
end | |
#gets the perimeter of the quads |
OlderNewer