Skip to content

Instantly share code, notes, and snippets.

@sk187
Last active August 29, 2015 14:25
Show Gist options
  • Save sk187/eb0f3397ee26b5ee2ad2 to your computer and use it in GitHub Desktop.
Save sk187/eb0f3397ee26b5ee2ad2 to your computer and use it in GitHub Desktop.
## First Hello world
puts "what is your name??"
name = gets.chomp
puts "Hi #{name}, how are you??"
#############
# Variables #
#############
name = "Sung"
puts "Hi #{name}"
########
name = "Sung"
puts "Hi #{name}"
name = "Bubba Sparxxx"
puts "Hey #{name}, what happened to Sung?"
###########
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 = 'Sung'
# last_name = "Kim"
# puts first_name + last_name
# seven = "7"
# puts seven.to_i
#############
# Methods #
#############
#def say_hi
# puts "Hi"
#end
# say_hi
# def greet
# name = "Sung"
# 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('Sung')
# say_hey('T-pain')
# some_name = "Joe Shmoe"
# say_hey(some_name)
## Multiple arguments
# def say_hey(name)
# puts "Hey, #{name}!"
# end
# say_hey('Sung')
# 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
######################
### Array 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
def word()
puts "Please enter a word"
word = gets.chomp.downcase
arr = []
while true
if word == ""
break
else
arr.push word
puts "Please input another word or hit enter"
word = gets.chomp.downcase
end
end
puts arr.sort
end
word() #this called the method, note there is nothing in the () as there is no argument to pass
#############
# 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 #
#########
# Download Postgresql
# rails new concert-app -d postgresql
# cd concert-app
# rails g scaffold Concert band:string date:date venue:string
# rake db:create
# rake db:migrate
# rails server (Your site is live on localhost:3000 )
# Open the App folder and then go to config -> routes.rb -> and then insert root 'concerts#index' on line 3 then save.
##############
# Deployment #
##############
# gem install heroku
# git init
# git add .
# git commit -m "initial commit"
# heroku login
# Follow Prompts
# heroku create
# git push heroku master
# heroku run rake:db migrate
# heroku start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment