Skip to content

Instantly share code, notes, and snippets.

View kkchu791's full-sized avatar

Kirk Chu kkchu791

  • Los Angeles, CA
View GitHub Profile
s = 'key=value'
array = s.split("=")
s1 = array[0]
s2 = array[1]
puts s1
puts s2
def method
a = 50
puts a
end
a = 10
method # calls method with local variable a = 50, then puts local varaible
puts a # puts the global variable a = 10 from line 6
1929
1951
1952
class Dog
attr_accessor :name
def bark
"#@name barks"
end
def eat
"#@name eats"
end
class Rectangle
attr_reader :area, :perimeter
def initialize(width, height)
@area = width * height
@perimeter = (width + height)*2
end
end
class UnpredictableString < String
def scramble
self.split("").shuffle.join("")
end
end
sentence = UnpredictableString.new("It was a dark and stormy night.")
puts sentence
puts sentence.scramble
@kkchu791
kkchu791 / shape.rb
Last active November 16, 2015 19:37
class Shape
def click
puts rotate
puts play
end
def play
sound
end
class Person
attr_accessor :balance
Inf = 1.0/0.0
def balance_test
puts "Your balance measurement is: #@balance"
case balance
when 500...Inf
"You could be a gymnast"
when 100...500
@kkchu791
kkchu791 / shape.rb
Last active November 16, 2015 08:28
class Shape
def click
p rotate
play
end
def play
sound
end
class UnpredictableString < String
def scramble(string)
string.split("").shuffle.join("")
end
end
sentence = UnpredictableString.new
p sentence.scramble("It was a dark and stormy night.")