####Methods to Know
-
.each
-
.map
-
.inject
-
.reject
-
.length
-
.reverse
-
.push
-
.pop
-
.shift
-
.unshift
-
.class
-
.inspect
puts "what is your first name" first = gets.chomp (removes the line breaks) puts "you typed #{first}" puts first.inspect def full_name(first, last) return "Hello #{first} #{last}" end
##seperate logic from presentation/modular. Should be data and logic as opposed to outputting to the screen
puts "what is your first name"
first = gets.chomp (removes the line breaks)
puts "what is your last name"
last = gets.chomp
full_name(first, last)
a = 7
1 = 0
while ( a <= 20)
puts a, i
i +=1
end
unless (a == 3)
puts "not 3"
end
if (a != 3)
puts "this is also not 3"
end
case a
when 5
puts "this is 5"
when 6
puts"this is 6"
else
puts "something different"
end
-
LONG WAY
class Rectangle attr_accessors :width, :height def inititalize (passed_in_width, passed_in_height) @height = passed_in_height @width = passed_in_width end def area @height * @width end #reader method def width @width end def height @height end #writer method def width=(width) @width = width end def height=(height) @height = height end end
require 'pry'
class Rectangle
attr_accessors :width, :height
def inititalize (passed_in_width, passed_in_height)
@height = passed_in_height
@width = passed_in_width
end
def area
@height * @width
end
end
require 'pry'
class Rectangle
attr_accessors :width, :height
def inititalize (passed_in_width, passed_in_height)
@height = passed_in_height
@width = passed_in_width
end
def area
@height * @width
end
end
class Square < Rectangle
def initialize(side)
super(side, side)
end
end
a = Rectangle.new(5,4)
b = Square.new(8)
binding.pry