Last active
August 29, 2015 14:15
-
-
Save Cspeisman/1878c21e8b9509bd5e4b to your computer and use it in GitHub Desktop.
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
## First Hello world | |
puts "what is your name??" | |
name = gets.chomp | |
puts "Hi #{name}, how are you??" | |
############# | |
# Variables # | |
############# | |
name = "Corey" | |
puts "Hi #{name}" | |
######## | |
name = "Corey" | |
puts "Hi #{name}" | |
name = "Bubba Sparxxx" | |
puts "Hey #{name}, what happened to Corey?" | |
########### | |
a = 7 | |
b = 10 | |
# puts a | |
# puts b | |
# puts a + a | |
# puts a + b | |
# c = a * b | |
# puts c | |
# puts c / b | |
# Ruby Operator # | |
# puts c / b == a | |
# puts a != b | |
### String concatenation ### | |
# first_name = 'Miles' | |
# last_name = "Davis" | |
# puts first_name + last_name | |
# seven = "7" | |
# puts seven.to_i | |
############# | |
# Methods # | |
############# | |
#def say_hi | |
# puts "Hi" | |
#end | |
# say_hi | |
# def greet | |
# name = "Corey" | |
# puts "Greetings #{name}" | |
# end | |
# greet | |
# def greetings | |
# puts "what is your name" | |
# name = gets.chomp | |
# puts "Greetings #{name}" | |
# end | |
# greetings | |
## passing arguments to methods ## | |
# def say_hey(name) | |
# puts "Hey, #{name}!" | |
# end | |
# say_hey('Corey') | |
# say_hey('T-pain') | |
# some_name = "Joe Shmoe" | |
# say_hey(some_name) | |
## Multiple arguments | |
# def say_hey(name) | |
# puts "Hey, #{name}!" | |
# end | |
# say_hey('Corey') | |
# say_hey('T-pain') | |
# some_name = "Joe Shmoe" | |
# say_hey(some_name) | |
## Calculator ## | |
# def add(a,b) | |
# a + b | |
# end | |
# puts add(4, 5) | |
# puts add(10, 40) | |
# puts add('Biggie ', 'Smalls') | |
# def subtraction(a,b) | |
# puts a - b | |
# end | |
# subtraction(30, 10) | |
# def multiply(a, b) | |
# a * b | |
# end | |
# def division(a,b) | |
# puts a / b | |
# end | |
# division(28, 7) | |
# division(30, 7) | |
# division(30.0, 7.0) | |
## Conditional | |
# def user_auth(user) | |
# username = "Zoidberg" | |
# if user == username | |
# puts "Welcome back #{username}" | |
# else | |
# puts "We dont know you. Sign up!" | |
# end | |
# end | |
# user_auth('C-smooth') | |
# user_auth('Zoidberg') | |
############# | |
# Arrays ## | |
############# | |
# list = ['one', 'two', 3] | |
# puts list[0] | |
# puts list[2] | |
# usernames = [] | |
# usernames << 'Csmooth' | |
# usernames << 'Ovechkin8' | |
# usernames << 'LL-CoolJ' | |
# usernames.each do |username| | |
# puts username | |
# end | |
# puts usernames.sort | |
###################### | |
### DICTIONARY SORT ### | |
######################## | |
# prompt user to enter a word | |
# then tell user to type another word or hit enter | |
# if the user enters a word prompt the user again | |
# if the user does not type in a word sort all the words the user typed | |
puts "Please enter a word" | |
word = gets.chomp | |
arr = [] | |
while true | |
if word == "" | |
break | |
else | |
word = gets.chomp | |
puts "Please input another word or hit enter" | |
word = gets.chomp | |
end | |
end | |
############# | |
# Hashes ## | |
############# | |
# user1 = { username: "Csmooth", birthday: "12-31-87", gender: "M"} | |
# puts user1[:username] | |
# puts user1[:gender] | |
# users = [ | |
# { username: "Csmooth", birthday: "12-31-87", gender: "M"}, | |
# { username: "LL-CoolJ", birthday: "12-31-73", gender: "M"}, | |
# { username: "GraceHopper", birthday: "12-9-06", gender: "F"} | |
# ] | |
# users.each do |user| | |
# puts user[:username] | |
# puts user[:gender] | |
# end | |
#################### | |
# Object Oriendted # | |
#################### | |
# class Person | |
# def initialize | |
# puts "I was created!!" | |
# end | |
# end | |
# class Box | |
# def initialize(w,h) | |
# @width = w | |
# @heigth = h | |
# end | |
# end | |
# | |
# box1 = Box.new(10, 5) | |
# p box1 | |
######## | |
# class Box | |
# def initialize(w,h) | |
# @width = w | |
# @height = h | |
# end | |
# | |
# def width | |
# @width | |
# end | |
# | |
# def height | |
# @height | |
# end | |
# | |
# def area | |
# self.height * self.width | |
# end | |
# end | |
# | |
# box1 = Box.new(10, 5) | |
# p box1.area | |
####### | |
# class Box | |
# attr_accessor :width, :height | |
# def initialize(w,h) | |
# @width = w | |
# @height = h | |
# end | |
# | |
# def area | |
# self.width * self.height | |
# end | |
# | |
# end | |
# | |
# box1 = Box.new(10, 5) | |
# p box1.area | |
# box1.height = 20 | |
# p box1.area | |
########### | |
# Rails ### | |
########### | |
# rails new concert-app | |
# cd concert-app | |
# rails g scaffold Concert band:string date:date venue:string | |
# rake db:migrate | |
# rails server | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment