Skip to content

Instantly share code, notes, and snippets.

View kkchu791's full-sized avatar

Kirk Chu kkchu791

  • Los Angeles, CA
View GitHub Profile
class Logger
def self.log(random)
File.open("./logfile.txt", "a") { |f| f.puts "#{random}" }
end
end
class Charlie
def random_number
Logger.log(rand(10000000))
end
#Write a class called Person that has balance as an instance variable and make it readable via an accessor.
class Person
attr_reader :balance
def initialize
@balance = 400
end
end
@kkchu791
kkchu791 / mixin1.rb
Last active November 15, 2015 21:52
# how do you mix module "Mixin" into class Charlie, such that I can call Charlie.method1?
module Mixin
def method1
"method1"
end
end
class Charlie
include Mixin
@kkchu791
kkchu791 / person.rb
Last active November 14, 2015 23:56
class Person
attr_reader :balance
def balance(balance)
@balance = balance
end
def balance_test?
p "Your balance measurement is: #{@balance}"
if @balance > 500
@kkchu791
kkchu791 / person.rb
Last active November 15, 2015 00:06
class Person
attr_accessor :balance
def balance_test?
p "Your balance measurement is: #{@balance}"
if @balance > 500
"You could be a gymnast"
elsif @balance > 100 && @balance < 500
"You have normal balance"
else
def save_game(file)
score = 1000
open(file, "w") do |f|
f.puts(score)
f.puts(Time.new.to_i)
end
end
def load_game(file)
open(file, "r") do |f|
class Person
attr_accessor :balance
def balance_test
p "Your balance measurement is: #{@balance}"
case @balance
when 500...1000
"You could be a gymnast"
when 100...500
"You have normal balance"
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.")
@kkchu791
kkchu791 / shape.rb
Last active November 16, 2015 08:28
class Shape
def click
p rotate
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