Skip to content

Instantly share code, notes, and snippets.

puts"Question\n Let’s start with an easy one. Write the expression 1+1 in two different, but equivalent ways."
puts"Answer\n 1+(1),1.0+(1)"
puts"Question\n Assume someone buys a product from your website for $33.50. You don’t trust float money. Can you think of something you can do to help you keep track of that value?"
puts"Answer\n33.50*100.to_i"
puts"Question \nMost things in Ruby are “introspectable”, meaning you can find out what something is and what it can do. Introspection helps you learn the language. Even a list of methods is introspectable. For example, the list of methods has methods. Output the list of methods available on a list of methods. There should be a sort method in that list. What does it do?"
puts"Answer \nThe sort method puts whatever you are sorting in alphabetical order."
puts"Question \n Type a number large enough such that calling the “class” method returns Bignum rather than Fixnum. How many digits long was it?"
puts"Answer\nTwenty digits"
puts"Question\nIf you round -1.5, is the
puts "Please enter your bill amount"
amount = gets.to_f
tip_percent = 0.20
tip = amount * tip_percent
total = amount + tip
puts total
def max (number1, number2)
if number1 > number2
puts number1
else
puts number2
end
end
max(10,5)
def add_two(number)
if number.respond_to? :+
if number.respond_to? :push
number.push 2
elsif number.class == String
number + "2"
else
number + 2
end
(1..100).each {|i|
if i % 3 == 0 and i % 5 != 0
i = "Fizz"
elsif i % 5 == 0 and i % 3 != 0
i = "Buzz"
elsif i % 3 == 0 and i % 5 == 0
i = "FizzBuzz"
end
puts i }
def max_refactor (*rest)
puts rest.max
end
a = (Object.methods).sort + (Kernel.methods).sort + (BasicObject.methods).sort
puts a.sort.uniq
puts "String To Number"
puts "'A'.to_i"
puts "\n"
def convert_the_letter_A_into_a_Fixnum(s, *rest)
s.to_i if s.respond_to? :to_i
end
puts "Test Results"
def test_convert_the_letter_A_into_a_Fixnum
puts convert_the_letter_A_into_a_Fixnum("A") == 0
module EqualL
def side
@side1
end
end
class Quadrilateral
def initialize(side1, side2, side3, side4)
@side1 = side1
@side2 = side2
module WyncodeMethods
def self.convert_the_letter_A_into_a_Fixnum(s, *rest)
s.to_i if s.respond_to? :to_i
end
def self.convert_to_interger(n, *rest)
n.to_i if n.respond_to? :to_i
end